Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » BeginnersRSS Feeds

ACCESSING VARIABLES USING POINTERS

Posted By: Adalgisal Fischer     Category: C Programming     Views: 4985

Write a program to illustrate the use of indirection operator '*' to access the value pointed to by a printer.

Code for ACCESSING VARIABLES USING POINTERS in C Programming

   main()                                                           
   {
       int   x, y;                                                  
       int   *ptr;                                                  
       x = 10;                                                      
       ptr = &x;                                                    
       y = *ptr;                                                    
       printf("Value of x is %d\n\n",x);                            
       printf("%d is stored at addr %u\n", x, &x);                  
       printf("%d is stored at addr %u\n", *&x, &x);                
       printf("%d is stored at addr %u\n", *ptr, ptr);              
       printf("%d is stored at addr %u\n", y, &*ptr);               
       printf("%d is stored at addr %u\n", ptr, &ptr);              
       printf("%d is stored at addr %u\n", y, &y);                  
       *ptr = 25;                                                   
       printf("\nNow x = %d\n",x);                                  
                                                                    
   }                                                                
Output                                                           
   Value of x is 10                                                 
   10     is stored at addr 4104                                        
   10     is stored at addr 4104                                        
   10     is stored at addr 4104                                        
   10     is stored at addr 4104                                        
   4104 is stored at addr 4106                                      
   10     is stored at addr 4108                                        
  Now x = 25                                                     
  
Share: 


Didn't find what you were looking for? Find more on ACCESSING VARIABLES USING POINTERS Or get search suggestion and latest updates.

Adalgisal Fischer
Adalgisal Fischer author of ACCESSING VARIABLES USING POINTERS is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!