Unexpected output while printing the address of a variable of char datatype

I am using Far manager for coding in c++

the code i wrote :
#include
using namespace std;
int main()
{

int a(5);

float b(3.14);

char ch = ‘A’;

string s(“HELLO WORLD”);

//displaying the address of each

cout<<&a<<"\n"<<&b<<endl;

//now displaying the address of ch

cout<<&ch;

//this error is beacuse of operator overloading

cout<<endl;

//explicit typecasting from char* to void*

cout<<(void*)&ch<<endl;

cout<<&s;

return 0;
}

the unexpected output for cout<<&ch i got is
A(2-3 char which arent on my keyboard ) H@(one tree like char )
unfortunately we cant post pics on doubts section

for rest the output is correct


so in this
0x61feb8
0x61feb4
A├⌡H@║
0x61feb3
0x61fe98

this is the output
tell me what is this thing ’ A├⌡H@║ ’

Hey @kul_boii


The answer to this issue is explained very beautifully in this post.
The brief idea is just that when you do &ch, you get char* data type. So cout interprets char* as a sequence of characters or a string and prints as long as it doesn’t encounter a null in memory.

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

1 Like

thank you so much:) but whenever im clicking on rate your experience im getting page not found pls resolve it so i can rate u 5 star :slight_smile:

1 Like

Thanks @kul_boii :blush:
Will look into the rate your experience issue.