Logo 
Search:

C Programming FAQ

Submit Interview FAQ
Home » Interview FAQ » C ProgrammingRSS Feeds

C programming practical question 122

  Shared By: Adah Miller    Date: Jan 24    Category: C Programming    Views: 62

Answer:

int swap(int *a,int *b)
{
*a=*a+*b;*b=*a-*b;*a=*a-*b;
}
main()
{
int x=10,y=20;
swap(&x,&y);
printf("x= %d y = %d\n",x,y);
}


Answer
x = 20 y = 10


Explanation
This is one way of swapping two values. Simple checking will help understand this.

Share: 
 

Didn't find what you were looking for? Find more on C programming practical question 122 Or get search suggestion and latest updates.


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


Tagged: