Aristotle’s Sum of Parts

Test your C++ programming skills by solving the given puzzle about type promotion and usual arithmetic conversions.

Puzzle code

Carefully read the code given below:

Press + to interact
#include <iostream>
#include <type_traits>
int main()
{
char char1 = 1;
char char2 = 2;
// True if the type of char1 + char2 is char
std::cout << std::is_same_v<decltype(char1 + char2), char>;
}

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)

0 (false)

B)

1 (true)

C)

Undefined behavior

D)

Runtime error

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.