• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C++ question

Mears

Platinum Member
Say you let:
int x = 4;
char y = 4;

why does
cout << (x == y);
print 1 when:

cout << x << &quot; &quot; << y;
prints out 4 and some weird ascii symbol

yet if you change y to '4' you get 0 for the equality test and they both print out as 4 when printed out individually.
 
The == operator only takes the face value of the character but does not look up the coresponding ASCII value. The << operator has been overloaded so that it does the ASCII lookup.
 
Actually the == operator returns a boolean value, 0 = false and 1 = true. So when you use cout << (x == y); it is the same as cout << true;


🙂atwl
 
Actually the == operator returns a boolean value, 0 = false and 1 = true.

And? What does that have to do with it?

I was referring to the method of how it calculates the boolean value. It only takes the raw value of the character instead of doing the ASCII lookup.
 
int x = 4;
char y = 4;


Sorry I didn't notice y is type char. That's why I didn't understand what you were trying to say.


🙂atwl
 
Back
Top