Vidyalelo
C++ Programming · Q21

Variables and Data Types in C++

Programming · C++ Programming · question 21

Q21

What will be the output of the following code: cout << (5 != 2); in C++?

A.
5
B.
2
C.
1
Answer
D.
Compiler error

Answer: Option C

Solution

Answer: Option C
Solution:
The output of the code cout << (5 != 2); in C++ will be 1.

The expression (5 != 2) is a comparison operation that checks if 5 is not equal to 2.

Since 5 is indeed not equal to 2, the expression evaluates to true.

In C++, the boolean value true is represented by 1.

Therefore, the output will be 1. However, it seems there might be a misunderstanding. The correct answer should be Option C: 1. If the options provided are fixed, then the answer should be corrected to reflect the boolean output as 1.