While I was coding, I came to a place where I need to use if and the & operator. For any reason, it did not work and I was frustrated.
The example code is here:
#include <iostream>
using namespace std;
int main()
{
int a=0, b=0,c=0;
if(a && b && c==0)
{
cout<<"Sound!";
}
return 0;
}
My goal is: if a and b and c is 0, I will print Sound!
The output that I got did not print anything but the compiler did not raised any errors.
But I thought that the output should be like this:
Sound!
I have tried to replace the && with only 1 & but it did not work. I had the & replaced with and but still did not work.
Does anyone know the answer?
>Solution :
You can write the if statement in several ways. For example
if (a == 0 && b == 0 && c==0)
or
if ( !a && !b && !c )
or
if ( not ( a != 0 || b != 0 || c != 0 ) )