I'm trying to understand what happens in the comparison statement below.
int n = 1;
std::puts( ((char*)&n)[0] == 1 ? "-Y-" : "-N-" );
The statement above's output for me is -Y-
My first question is, why cast the pointer to a char*
instead of an int*
?
Also, if we are comparing a char to an int, it seems like the answer should be -N-
.
Does the char automatically get converted to an int when comparing to 1
?