Advertisement
Md_hosen_zisad

pointer swap

Oct 31st, 2017
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.26 KB | None | 0 0
  1. #include<stdio.h>
  2. void swap(int *x,int *y)
  3. {
  4.  int t;
  5.  t=*x;
  6.  *x=*y;
  7.  *y=t;
  8.  
  9.  
  10. }
  11. int main()
  12. { int a=20,b=30;
  13. a=a+b;
  14. b=a-b;
  15. a=a-b;
  16.    printf("value before swap : %d %d\n \n",a,b);
  17.    swap(&a,&b);
  18.    printf("value after swap: %d %d",a,b);
  19.    return 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement