
please wait
|
|
cout << "Address of variable : " << &pointer << "\n\n";
&pointer
is the address of the pointer. &anything
is the address of the anything (well, more accurately, a pointer holding the address of the anything).cout << "Address of pointer : " << pointer << "\n\n\n";
pointer = &var;
|
|
Address of p: 0x7ffc6a617f60 Value of p: 0x7ffc6a617f6c Address of n: 0x7ffc6a617f6c Value of n: 42 Value of *p: 42 |
int* A = &var
int** B = &A
toasty wrote: |
---|
A pointer is just an address |
|
|
dutch wrote: |
---|
A pointer is an object that holds an address. |
|
|
|
|
|
|
This is just semantics. |
You're the faggot that said terminology was important. |
dutch wrote: |
---|
You're the faggot that said terminology was important. What a fucking liar! |
|
|
&var
as a pointer, just like you would refer to 5.0
as a double versus calling it a "double precision floating point literal." C++ specifically refers to double precision floating point values as "double," but other languages may use a different term for it. Terminology is indeed important, and thus I used the terminology "pointer," which is consistent with the terminology used for the rvalues of all other primitive data types like double and float. &var
, since it is just an rvalue of a pointer type.it is not wrong to refer to &var as a pointer |
I'd say it's only similar to a pointer. A pointer itself is a container for a memory address. |
5.0
, we typically say "that's a double," and when we see 5.0f
we say "that's a float." It's all a matter of perspective. Though I understand others may not hold the same opinion on this, it's just the terminology that I believe makes more sense when referring to rvalues of a specific data type like int*. My view is consistent with how we treat every other data type in C++. I believe OP's confusion stemmed from the different terminology used by programmers to refer to rvalues of pointer types (addresses), which is why I simply used the term "pointer"when we see something like 5.0, we typically say "that's a double," |
I've actually always found that a bit strange. I've always separated types with values, opting instead to say, "it's a decimal number, so you should use a double to store it." |
5.0
and 5.0f
are two different types of "double" and "float" respectively. To me, calling both of them a "decimal number" seems ambiguous, since they are two different types, but to each his own, I guess. I just use the term that makes sense to me in that particular context.I don't know what's up with dutch; he's been acting this way for a while now. Not sure if his behavior is something new or if he's always been like this. |
Frustration aside, dutch is right. A pointer is an object that may hold the address of another object. It is not an address. |
&var
a pointer itself. It technically is an rvalue of a pointer type. You can dereference it: *&var
. It can be set to a variable: auto var = &intvar
, in which case you would say that "var is being initialized with an int* (int pointer)," which is technically correct because &intvar
is an rvalue of type int*, which is a pointer. My justification for this is the same reason we call rvalues of other primitive types like double and float as the name of the type itself.5.0
is a double (rvalue of type double)5.0f
is a float (rvalue of type float)&intvar
is an int* (rvalue of type int*), or simply a pointer for short.&intvar
is inherently and will always be deduced as an int* (an int-pointer). The reason I called it a pointer is for OP to understand that, because it seemed that his confusion was the different terminology used for pointer rvalues (which are addresses).I apologize for not subscribing to whatever religion it is that forces programmers to speak like a textbook on every issue |
You can technically use the terms "address" and "pointer" interchangeably |