Puzzle 13A Constant Struggle

 #include <iostream>
 #include <type_traits>
 
 template​ <​typename​ T>
 void​ byValue(T t)
 {
  std::cout << std::is_const_v<T>; ​// true if T is const
 }
 
 template​ <​typename​ T>
 void​ byReference(T &t)
 {
  std::cout << std::is_const_v<T>; ​// true if T is const
 }
 
 int​ main()
 {
 int​ nonConstInt = 0;
 const​ ​int​ constInt = 0;
 
  byValue(nonConstInt);
  byValue(constInt);
 
  byReference(nonConstInt);
  byReference(constInt);
 }

Guess the Output

images/aside-icons/important.png

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

The program displays the following output:

 0001

Discussion ...

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.