this code
#include <iostream>
using namespace std;
int main(){
bool t=false;
cout<<t &&(!t)<<endl;
return 0;
}
shows me error like this
invalid operands of types ‘bool’ and ” to binary
‘operator<<‘
What is wrong? I can’t understand this, please explain it to me. I think that && and ! is defined in c++.
So what is wrong?
This means that the second
<<operator is trying to execute on (!t) and ‘endl’.<<has a higher precedence than&&so your cout statement executes like this:(cout << t ) && ( (!t) << endl );Add parenthesis to fix this:
cout << (t && (!t) ) << endl ;Look here for order of operations when statements are not evaluating as expected.