openfrog
openfrog

Reputation: 40755

Is there a difference between a so called "Variable" and a so called "Pointer"?

I always wonder if it's correct to say that something like THIS is a "pointer", rather than a "variable":

NSString *fooStr = ...;

Would you call "fooStr" a "pointer" rather than a "variable"? Or is it okay to say both here?

Upvotes: 1

Views: 137

Answers (2)

pixel
pixel

Reputation: 5298

Short answer:

A pointer is a variable that contains the location of data memory, whereas a variable contains the data itself.

So you CAN call a pointer a variable, but calling it a pointer is more specific.

Upvotes: 9

dacracot
dacracot

Reputation: 22358

A pointer's data type is always an address. A variable's data type is what you set it to.

Upvotes: 2

Related Questions