Once stackPtr
is passed in (by value), it is a local (automatic) variable, and modifying it doesn't affect any of the caller's automatic variables. However, when you do:
*stackPtr = node;
you're modifying the object it points to.
Once stackPtr
is passed in (by value), it is a local (automatic) variable, and modifying it doesn't affect any of the caller's automatic variables. However, when you do:
*stackPtr = node;
you're modifying the object it points to.
*stackPtr = node;
This dereferences stackPtr
and sets the object pointed at to the value of node
.
stackPtr = &node;
This changes the pointer stackPtr
to point to the node
pointer which is allocated on the stack.
Basically, in the first case, you are changing the thing that the pointer refers to (called the referent of the pointer) but the pointer itself remains unchanged. In the second case, you are changing the pointer to refer to something different.