| arrays/03_swap.c - Funktionen swap og et hovedprogram, som kalder swap på to variable. | Lektion 9 - slide 11 : 30 Program 3 |
#include <stdio.h>
void swap(int *p, int *q){
int tmp;
tmp = *p;
*p = *q;
*q = tmp;
}
int main(void){
int a = 3, b = 7; /* We want to exchange the values of a and b */
printf("%d %d\n", a, b); /* 3 7 is printed */
swap(&a, &b);
printf("%d %d\n", a, b); /* 7 3 is printed */
return 0;
}