Zeiger bei Funktionsaufruf
By Matthias Fechner
Code
#include <stdio.h>
/* programm to see who a pointer work with functions
Written by Matthias Fechner
*/
void callByValue(int);
void callByReference(int*);
int main(void) {
int i;
i=1;
printf("i=%d\n",i);
callByValue(i);
printf("i=%d\n",i);
callByReference(&i);
printf("i=%d\n",i);
return 1;
}
void callByValue(int i) {
printf("i=%d\n",i);
i=8;
printf("i=%d\n",i);
return;
}
void callByReference(int *i) {
printf("i=%d\n",*i);
*i=13;
printf("i=%d\n",*i);
return;
}
Result
~/c_tutor> gcc pointer_func.c idefix@idefix_mobil
~/c_tutor> ./a.out idefix@idefix_mobil
i=1
i=1
i=8
i=1
i=1
i=13
i=13