marcelofoxes

simple value swapping using C pointers

Oct 31st, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.31 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. void swapThem(int *a, int *b) {
  5.   int aux = *b;
  6.   *b = *a;
  7.   *a = aux;
  8. }
  9.  
  10. int main(int argc, char const *argv[]) {
  11.     int a = 2;
  12.     int b = 5;
  13.  
  14.     printf("Before: a is %d b is %d\n", a, b);
  15.     swapThem(&a, &b);
  16.     printf("After: a is %d b is %d\n", a, b);
  17. }
Advertisement
Add Comment
Please, Sign In to add comment