Pointer Understanding

This is my second course and I had some difficulty understanding the power and reason for pointers. Something like this (but in code) made it finally “click”. I will use a simplified version.

MyState = Happy (I’m Happy. You do not yet exist.)
YourState = MyState (I’m Happy. You’re Happy.)
MyState = Sad (I’m Sad. You’re Happy.)

Your state is only the same as mine at the time of assignation or initialization but then it has a “life of it’s own”.

But if you do this…

MyState = Happy
*YourState = MyState
MyState = Sad

Now your state is sad just like me! Your state will always be the same as mine even if something changes my state in the future.

I imagine a pointer as an inverted reflection or a projection so we need to de-reference it to “flip it back around” otherwise it only shows the actual address of the memory (which is all a pointer really is) instead of the data the memory holds.

Also a pointer is small and fixed in size (I believe). It is likely much easier to manipulate, copy, move etc. than the data itself which may be enormous. Like having a bank statement and checkbook instead of carrying around all your wealth like a pirate which can be fun but extremely inconvenient!

This is my limited understanding so far but it helped me incredibly during my first C++ course.

1 Like

Thankyou thankyou thankyou thankyou! it was enough. I’m not an english native speaker so i didn’t get it clearly until i get your resume.

Thankyou again bro!

1 Like

Privacy & Terms