Puzzle 3Hack the Planet!

 #include <iostream>
 
 int​ ​getUserId​() { ​return​ 1337; }
 
 void​ ​restrictedTask1​()
 {
 int​ id = getUserId();
 if​ (id == 1337) { std::cout << ​"did task 1​​\n​​"​; }
 }
 
 void​ ​restrictedTask2​()
 {
 int​ id;
 if​ (id == 1337) { std::cout << ​"did task 2​​\n​​"​; }
 }
 
 int​ ​main​() {
  restrictedTask1();
  restrictedTask2();
 }

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 has undefined behavior! But it might display the following ...

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.