References and pointers

image

So, after repointing the pointer valPtr points to a different address which contains val2.

After rewriting the value at the pointer the pointer obtained a new value which changed the previously pointed variable, changing its value as well.

valRef stored the address of val1, so when we change the value stored in valRef we’re changing the value stored in val1.

Privacy & Terms