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

28 lines
403 B
C
Raw Normal View History

2021-10-12 09:20:11 +02:00
/* Inversion de variables */
#include <stdio.h>
#include <stdlib.h>
2021-10-12 10:46:13 +02:00
void inverser(int*, int*);
2021-10-12 09:20:11 +02:00
int main() {
int var1 = 123;
int var2 = 18;
printf("var1=%d et var2=%d\n", var1, var2);
2021-10-12 10:46:13 +02:00
inverser(&var1, &var2);
2021-10-12 09:20:11 +02:00
printf("var1=%d et var2=%d\n", var1, var2);
return 0;
}
2021-10-12 10:46:13 +02:00
void inverser(int* var1, int* var2) {
int tmp;
tmp = *var1;
*var1 = *var2;
*var2 = tmp;
}