Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » BeginnersRSS Feeds

Passing of pointers as function parameters

Posted By: Nicole Hughes     Category: C Programming     Views: 3569

Write a function using pointers to exchange the values stored in two locations in the memory.

Code for Passing of pointers as function parameters in C Programming

void exchange (int *, int *);        /* prototype */
main() { int x, y; x = 100; y = 200; printf("Before exchange : x = %d y = %d\n\n", x, y); exchange(&x,&y); /* call */
printf("After exchange : x = %d y = %d\n\n", x, y); } exchange (int *a, int *b) { int t; t = *a; /* Assign the value at address a to t */
*a = *b; /* put b into a */
*b = t; /* put t into b */
} Output Before exchange : x = 100 y = 200 After exchange : x = 200 y = 100
  
Share: 


Didn't find what you were looking for? Find more on Passing of pointers as function parameters Or get search suggestion and latest updates.

Nicole Hughes
Nicole Hughes author of Passing of pointers as function parameters is from London, United Kingdom.
 
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!