| swap.c - A C program with a swap function. | Lecture 1 - slide 28 : 34 Program 1 |
#include <stdio.h>
void swap_doubles_ptr(double *d1, double *d2){
double temp;
temp = *d1;
*d1 = *d2;
*d2 = temp;
}
int main(void) {
double e, f;
e = 5.0, f = 7.0;
printf("%f %f\n", e, f); // 5.0 7.0
swap_doubles_ptr(&e, &f);
printf("%f %f\n", e, f); // 7.0 5.0
return 0;
}