-
pointers and array
hi everybody,
today i was reading a tutorial on C++ on <http://www.cplusplus.com/doc/tutorial/pointers/> and there it is wriitten in pointer and array Initialization section:"It is important to indicate that terry contains the value 1702, and not 'h' nor "hello", although 1702 indeed is the address of both of these."
Now i write a very simple program and compile it with gcc:
Code:
#include<iostream>
using namespace std;
int main(){
char * terry = "hello";
cout << terry << endl;
}
and its output is : "hello"
If terry does not contain "hello", the output should have been some address.
Pls help me to understand the concept.
Regards,
arpanm
-
char* is a special case, in that 99.9% of the time it makes more sense to print the string it points to rather than the pointer itself.
To print the actual pointer itself, try
Code:
cout << reinterpret_cast <void*> (terry) << endl;