p
is a pointer to
I
and
scanf
needs a pointer n order to know where to put the value it reads.
This is normal, because in C everything is passed t a function
by value not
by reference - which means that the function gets a copy of the variable rather than the variable itself. That makes a lot of sense if you thin about it:
void foo(int x)
{
x = x +1;
printf("%d\n");
}
Is fine, but what would happen if you called it like this:
foo(666);
If you didn't take a copy of the value, you would have the code trying to change the value of a constant number!
So if you want to change something in the calling function from the called function, you have to pass a pointer rather than the value, so a copy of the pointer is passes which points at the same place as the original.