44.4k views
0 votes
What is the output of this program? int n = 4; cout << (n == 4) << endl; cout << (n > 3) << endl;

1 Answer

1 vote

Final answer:

The output of the program is two lines with the number 1, as both conditions tested are true, and in C++, true is represented by the integer 1.

Step-by-step explanation:

The output of the program can be understood by analyzing the two conditions in the cout statements. The first cout statement tests if the variable n is equal to 4, (n == 4), which it is, so it outputs 1 as true. The second cout statement tests if n is greater than 3, (n > 3), which is also true, so it outputs 1 again. In C++, a boolean true is represented by the integer 1 and false by 0. Hence, the output of the program will be two lines, both with the number 1.

User Kyle Burkett
by
8.2k points