So just experimenting with pointers in C.
void inc(int *p){
++(*p);
}
int main(){
int x = 0;
int *p;
*p = x;
inc(p);
printf("x = %i",x);
}
Why is this printing "x = 0" instead of "x = 1"?
Here's your error:
*p = x;
You're dereferencing p, which is unassigned, and giving it the current value of x. So x isn't changed because you didn't pass a pointer to x to your function, and dereferencing an uninitialized pointer invokes undefined behavior.
You instead want to assign the address of x to p:
p = &x;
Alternately, you can remove p entirely and just pass the address of x to inc:
inc(&x);