Pointer [first-glance]
April 24, 2009
I am jumping beyond my level with C++ at this point: pointer variable. I was just giving my first (not really, my second) glance on it. But the powerful pointer is really amazing and attractive - wondering when....
Okay I hope what I am going to write is 99% correct - if not, please leave a comment and discuss with me.
What is pointer? Well, I would just simply treat pointer as "pointer" in English. In English it means something is used to indicate something. In programming, we can say, "pointer is a tool to point at an object".
In another word, in terms of C++ and programming theory, that first, we know a variable is treated as directly reference to a value, and so a pointer, we can say, it's indirectly reference to a value.
Try to picture pointer as something has to do with "address", the sample code below will give you a very brief relationship among the pointer, variable and the value.
1 2 3 4 5 6 7 8 9 10 | #include <iostream> using namespace std; int main() { int a = 11; int * aPtr = &a; cout < < "\nAt address " << aPtr << ", the value " << *aPtr << " is stored.\n"; } |
Outcome:
At address 0x0053AD78, the value 11 is stored.
(more...)