What does the following function do? Its output is foobar(k) = 7, k = 7
.
int foobar(int* n){
*n = *n +1;
return *n;
}
int k = 6;
printf("foobar(k) = %d,",foobar(&k) );
printf(" k = %d\n", k);
What does the following function do? Its output is foobar(k) = 7, k = 7
.
int foobar(int* n){
*n = *n +1;
return *n;
}
int k = 6;
printf("foobar(k) = %d,",foobar(&k) );
printf(" k = %d\n", k);
The function foobar simply take an integer pointer as input parameter. On the code increase the content of that pointer by 1 and then returns the content of pointer. When you call fooar by this way: foobar(&k) in fact you passing foobar pointer of k variable (that's what foobar expected) when using *n in code you mean that you working with content of pointer (not pointer itself)