Home > Mobile >  What is the output of this C Program? chars are stored as ASCII values?
What is the output of this C Program? chars are stored as ASCII values?

Time:12-08

char char_ = '3';
unsigned int * custom_mem_address = (unsigned int *) &char_;
cout<<char_<<endl;
cout << *custom_mem_address<<endl;

Since custom_mem_address contains one byte value of char '3', I except it to contain the ascii value of '3' which is 51. But the output is the following.

3 1644042035

Depending on the byte alignment at least one byte in the 1644042035 should be 51 right? But its not. Can you please explain.

Can someone explain where am I wrong

CodePudding user response:

1644042035 in binary is 0110 0001 1111 1110 0001 0111 0011 0011 and 51 is 0011 0011.

0110 0001 1111 1110 0001 0111 0011 0011

0000 0000 0000 0000 0000 0000 0011 0011

Isn't that what you are looking for?

  •  Tags:  
  • c
  • Related