What is the output of the given program and why?

#include<iostream>

using namespace std;

int main()

{

if (!(cout << "abc" ))

cout << " abc " ;

else

cout << "def" ;

return 0;

}

output will be : abcdef

cout << "abc" which returns a non-zero value,
!(non-zero value) is false,
hence it executes else .
Hence technically it only executes else block

1 Like

The program will return the following output :
abcdef

This will be the output because the first cout in the if the condition will give you the output ‘abc’ and return a non zero value with, will negate to a negative one. This runs the else condition and the ‘def’ will be returned to the output screen.

1 Like