A Constant Struggle
Test your C++ programming skills by solving the given puzzle about template argument deduction.
We'll cover the following
Puzzle code
Carefully read the code given below:
#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);}
Your task: Guess the output
Try to guess the output of the above code. Attempt the following quiz to assess your understanding.
Q
What is the expected output of the above code?
A)
0000
B)
0001
C)
0101
D)
1010
Let’s discuss this code and output together in the next lesson.
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.