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”.