param dereference

First, we have a variable called aNum. That variable has an address, with an associated value:



We then have:

We have an integer pointer point to the address of our aNum variable.



Then we have a function definition:

We use that function like this:

The function gets pushed onto the main function stack. The function returns void so we do not push any return variables onto the stack. Next, the function has

as its parameter. Hence, that parameter gets pushed onto the stack like so:

param_deref_3

The parameter variable param points to whatever intPtr is pointing to…which is aNum’s address.

In our function definition, param gets dereferenced. This means that it gets the value associated with the address that it is pointing to. In our case its the value of aNum, which is 100. It changes it to 45.

param_deref_4

When the function call ends, the whole function with its parameter list gets popped. All we’re left with is aNum, which value has been changed to 45.
the pointer numPtr which points to the address of aNum, and thus, also will get 45 if we dereference it.
param_deref_5

Sample Output

OUTSIDE: int * intPtr is: 100
OUTSIDE: someNumber is: 100
INSIDE: parameter pointer is DEREFERENCED…getting the original value which is: 100
INSIDE: original value changed to: 45

OUTSIDE: int * intPtr is: 45
OUTSIDE: someNumber is: 45

full source