I'm an average programmer in C++, and usually avoid pointers at all costs. But I have recently started using some APIs, that are just full of them. And honesty, they seem to work a lot better, if I just continue down a similar path, as that intended/implied by the author of the API.
In form and function, but obviously not syntax - Can "Pointers" be looked at as being, "even somewhat", analogous to "Cell References" in Microsoft Excel?
I have several years of experience with Microsoft Excel w/VB. I'm also sort of a "Formula/Reference Junkie", when it comes to using Excel, so this train of thought just makes sense to me. I just want to know if I'm "Pointed" in the right direction.
Thank You!
A cell reference in Excel is a string that indicates a certain location in a workbook (or, under certain circumstances, another workbook).
A pointer in C++ is a memory address. The memory address is a number (nothing more!) that locates a certain spot in virtual RAM.
So yes, they actually are rather similar. I was prepared to rain on your parade by talking about how different the two are. But the analogy works.
When you "dereference" a pointer, you're going to the spot in memory which it indicates. In Excel you don't really "dereference" the cell references. But close enough.
When you say int y = 4; int* x = &y;
, that's kind of like creating a cell at B1 containing "4", and then another cell that contains "=B1".
There are several analogies that spring to mind, but, the classic one when I first learnt computer programming was mail boxes in the mail room. Imagine mail boxes labelled, Tom, Dick and Harry.
In computer programming, Tom, Dick and Harry are all memory addresses. The first two contain pointers, the third, contains a numerical value. Opening the envelope in Tom or Dick's mailboxes are like dereferencing pointers.
We write this:
int harry = 100;
int *dick = &harry;
int **tom = &dick;
So, **tom == *dick == harry == 100. Whilst tom is a pointer to a pointer to harry. And dick is a pointer to harry.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With