C-Kurs/(Pointer) Swapping/Musterlösung: Unterschied zwischen den Versionen
< C-Kurs | (Pointer) Swapping
(Die Seite wurde neu angelegt: „ #include <stdio.h> void swap(int *x, int *y) { int t = *x; *x = *y; *y = t; } int main(){ int i= 1; int j= 2; printf("i: ...“) |
|||
Zeile 3: | Zeile 3: | ||
void swap(int *x, int *y) { | void swap(int *x, int *y) { | ||
− | + | ||
int t = *x; | int t = *x; | ||
*x = *y; | *x = *y; | ||
Zeile 15: | Zeile 15: | ||
int i= 1; | int i= 1; | ||
int j= 2; | int j= 2; | ||
− | + | ||
printf("i: %i j: %i\n", i, j); | printf("i: %i j: %i\n", i, j); | ||
− | + | ||
swap(&i, &j); | swap(&i, &j); | ||
− | + | ||
printf("i: %i j: %i\n", i, j); | printf("i: %i j: %i\n", i, j); | ||
} | } |
Version vom 24. September 2009, 08:40 Uhr
#include <stdio.h> void swap(int *x, int *y) { int t = *x; *x = *y; *y = t; } int main(){ int i= 1; int j= 2; printf("i: %i j: %i\n", i, j); swap(&i, &j); printf("i: %i j: %i\n", i, j); }