Address of char array

Pages: 12
Just curious. If I try an output of simply "&test" I also get an address value. But of what? Is it garbage value that actually has no usefull value?
A pointer is a piece of memory that holds a value. This value is the address of another piece of memory that holds the data.

&test is the address of the pointer.
Whats interesting to me is that we are saying &test[0] is equivalent to test. They have the same value, but they are different aren't they? An address (&test[0]) is just an address which could be pointing to any object...test is a pointer "with type", i.e. it is more than an address, it can be incremented in an intelligent way. So when cout encounters &test[0] how does it know it is a "pointer to a char".

Hope this makes sense.

Regards

i
Last edited on
When you declared test, you called it a char*. The operator[] turns it into a char, then & makes it a pointer again. That's how the compiler knows.
Topic archived. No new replies allowed.
Pages: 12