+ 1
Is this syntax is right ? if(n=0).
If yes then how?
5 Answers
+ 2
No, it is incorrect.
In c++, '=' acts as an assignment operator and assigns the value on RHS to LHS whereas '==' is an operator that checks equality of the RHS and LHS.
So it should be if(n==0) in case you want to check whether n is 0 or not.
+ 1
it should be == instead of =
0
No, it should be if(n==0) to check whether n has value 0 or not .
0
no, this assigns the value of 0, obviously it's not going to work well in this case, you have to use == which checks if the n is EQUAL TO 0
0
n=5;
if(n=0)
cout<<"zero";
else
cout<<"non zero ";
cout<<endl;
cout<<n;
what should be the output?