Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » BeginnersRSS Feeds

Program to illustrate the use of pointers in arithmetic operations

Posted By: Lilly Campbell     Category: C Programming     Views: 11694

Write a program to illustrate the use of pointers in arithmetic operations.

Code for Program to illustrate the use of pointers in arithmetic operations in C Programming

   main()                                                           
   {
       int  a, b, *p1, *p2, x, y, z;                                
       a  = 12;                                                     
       b  =  4;                                                     
       p1 = &a;                                                     
       p2 = &b;                                                     
       x  =  *p1 * *p2 - 6;                                         
       y  =  4*  - *p2 / *p1 + 10;                                  
       printf("Address of a = %u\n", p1);                           
       printf("Address of b = %u\n", p2);                           
       printf("\n");                                                
       printf("a = %d, b = %d\n", a, b);                            
       printf("x = %d, y = %d\n", x, y);                            
       *p2  = *p2 + 3;                                              
       *p1  = *p2 - 5;                                              
       z    = *p1 * *p2 - 6;                                        
       printf("\na = %d, b = %d,", a, b);                           
       printf(" z = %d\n", z);                                      
   }                                                                
                                                                    
Output                                                           
   Address of a = 4020                                              
   Address of b = 4016                                              
   a = 12, b = 4                                                    
   x = 42, y = 9                                                    
   a = 2, b = 7, z = 8 
  
Share: 



Lilly Campbell
Lilly Campbell author of Program to illustrate the use of pointers in arithmetic operations is from Toronto, Canada.
 
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!