Puzzle 25Weakly Typed, Strongly Puzzling
 #include <iostream>
 
 int​ ​main​()
 {
  std::cout << +!!​""​;
 }

Guess the Output

images/aside-icons/important.png

Try to guess what the output is before moving to the next page.

images/hline.png

The program displays the following output:

 1
images/hline.png

Discussion

Wait, what? Is this legal C++? What does it even mean, and why does it print 1?

While C++ is a statically typed language, it’s not particularly strongly typed. As we’ve ...

Get C++ Brain Teasers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.