efrei/programmation-c-cpp/tp1/inversion-variables.c

27 lines
403 B
C

/* Inversion de variables */
#include <stdio.h>
#include <stdlib.h>
void inverser(int*, int*);
int main() {
int var1 = 123;
int var2 = 18;
printf("var1=%d et var2=%d\n", var1, var2);
inverser(&var1, &var2);
printf("var1=%d et var2=%d\n", var1, var2);
return 0;
}
void inverser(int* var1, int* var2) {
int tmp;
tmp = *var1;
*var1 = *var2;
*var2 = tmp;
}