1#include <stdio.h>
2#include <stdlib.h>
3
4int main()
5{
6 //initialize variables
7 int num1 = 10;
8 int num2 = 9;
9 int tmp;
10
11 //create the variables needed to store the address of the variables
12 //that we want to swap values
13 int *p_num1 = &num1;
14 int *p_num2 = &num2;
15
16 //print what the values are before the swap
17 printf("num1: %i\n", num1);
18 printf("num2: %i\n", num2);
19
20 //store one of the variables in tmp so we can access it later
21 //gives the value we stored in another variable the new value
22 //give the other variable the value of tmp
23 tmp = num1;
24 *p_num1 = num2;
25 *p_num2 = tmp;
26
27 //print the values after swap has occured
28 printf("num1: %i\n", num1);
29 printf("num2: %i\n", num2);
30
31 return 0;
32}
33