You should have something like:
#include <iostream> using namespace std;
at the top of your program. Or you can omit using and refer to std::cin and std::cout .
int main() { char *p;
p is a pointer, but you did not initialize it, so it could point anywhere or anywhere. You need to initialize it, for example:
p = new char[100];
...
cin >> p; //forexample: haha
This is normal if you initialized p to point somewhere, except that you can overflow the buffer that it points to if you enter too much data. This is normal for a simple test program like this, but in practice you will want to take measures to avoid this.
char q = *p; cout << "&q = " << &q << endl;
&q is of type char* , a pointer to char . Sending the char* value to cout does not print the pointer value (memory address); it prints the line it points to. (Although I get some odd results when I run it myself, maybe something is missing.) If you want to see the value of the pointer, add it to void* :
count << "&q = " << (void*)&q << endl;
(Or you can use one of the C ++ specific casts, I'm not sure which is the best.)
cout << "q = " << q << endl;
Here q is just a char , so it prints its value as a character: h .
return 0; }
source share