A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-125.cpp
1#include<iostream>
2intmain(){
3unsignedintu=5;
4ints=-1;
5std::cout<<(s<u)<<"\n";
6return0;
7}
Conversions
Answer & explanation
Console output
0
Why
In a comparison between int and unsigned int, the usual arithmetic conversions turn the int into unsigned int. The value -1 becomes the largest unsigned value, which is greater than 5, so s < u is false and prints 0. This well-defined but surprising rule is a frequent bug source.