I recently developed an interest in C programming so I got myself a book (K&R) and started studying.
Coming from a University course in Java (basics), pointers a
In this example:
int f1(int i);
f1(x);
the parameter i
is passed by value, so the function f1
could not change the value of variable x
of the caller.
But in this case:
int f2(int* i);
int x;
int* px = &x;
f2(px);
Here we still pass px
parameter by value, but in the same time we pass x
by refference!. So if the callee (f2
) will change its int* i
it will have no effect on px
in the caller. However, by changing *i
the callee will change the value of x
in the caller.