c_programming_language/c_modern_approach/Pointers/exercises/e_4.c

22 lines
349 B
C

#include <stdio.h>
/**
* @brief Variable swapping exercide
*/
void swap(int *p, int *q) {
printf("*p: %d; p = %p\n", *p, p);
printf("*q: %d; q = %p\n", *q, q);
int x = *p;
int y = *q;
*p = y;
*q = x;
}
int main() {
int a, b;
a = 4;
b = 5;
printf("a = %d, b = %d\n", a, b);
swap(&a, &b);
printf("a = %d, b = %d", a, b);
}