8

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!

2
  • 2
    I am sorry to say that but if you are confused about pointers you are not an average C++ programmer. But keep up ! C++ is a wonderful language that will teach you a lot about computer science.
    – log0
    Jan 24, 2012 at 18:48
  • 1
    @Ugo - It is possible to write useful and efficient code in C++, without ever using a single pointer. It is also possible to mind your own business, if you don't have anything meaningful to share.
    – tahwos
    Jan 27, 2012 at 23:01

5 Answers 5

9

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

3
  • The last sentence in your reply, is what got me to thinking this way in the first place - because I do that ("=B1") all the time. The second sentence in your reply, is sort of my "disambiguation" that prompted my question - A cell reference in Excel, is a number "and letter" (nothing more), that locates a certain location in a worksheet. << there's my analogy. I like your answer, Thanks!
    – tahwos
    Jan 24, 2012 at 4:35
  • Consider the cell reference a named reference. In the Excel code there is most likely a function that converts this to an actual cell reference, possible signature: Cell * locateRef( char const * ref ). This named reference is in the spreadsheet domain, whereas the pointer reference is in the memory domain, but they both refer to the same thing. Jan 24, 2012 at 8:10
  • @edA-qa mort-ora-y, I didn't mean it quite so literally, but thanks for the input.
    – tahwos
    Jan 24, 2012 at 12:45
1

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 Tom's mail box, place an envelope that says there's a clue in Dick's mail box
  • In Dick's mail box, place an envelope that says the treasure is in Harry's mail box
  • In Harry's mail box, you put $100 dollars! Yippee!

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.

0

I think that's a reasonable analogy.

0

A pointer is nothing but an address of a memory that holds something (or nothing).

Regardless whether the cell actually contains any data, it's address, can be thought of a as a pointer to the cell.

Note that the cell itself is not a pointer.

-1

No, not really. Pointers can be indexed, and they can also be invalid, and I believe that neither of those things is true for Excel cells.

1
  • Both are true in Excel. You can index a range of cells, or even by the contents of a single cell. Invalid cells references are displayed as errors - #VALUE!, #DATA!, etc.
    – tahwos
    Jan 24, 2012 at 4:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.