Hi folks,
Fresh newbie here. I'm taking a c++ class and I'm just a beginner. We have started to learn pointers and I discovered some puzzling behavior while messing around with the address operator &
. Here is my code snippet:
char letter = 'a';
int integer = 1;
char letterarray[11] = "Char array";
cout << letter << "\t\t" << &letter << endl;
cout << integer << "\t\t" << &integer << endl;
cout << letterarray << "\t" << &letterarray << endl;
The addresses of the integer and character array output as clean hex numbers, but the char output looks strange:
a af
1 0x22ff68
Char array 0x22ff50
In fact the garbled output of the single character address changes depending on other code around it!
If it helps I'm using Dev-C++ 4.9.9.2 on a Windows XP machine, but I also get similar weird output on the Unix system at school.
I tried searching for any explanations on Google and these forums but didn't come up with anything. If there was an obvious search I could have made to find the answer, please let me know that too for future reference.
Thank you!