+ 1

Is this syntax is right ? if(n=0).

If yes then how?

3rd Dec 2016, 9:21 AM
Dharm Vashisth
Dharm Vashisth - avatar
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.
3rd Dec 2016, 11:41 AM
Samriddhi Jain
Samriddhi Jain - avatar
+ 1
it should be == instead of =
24th Aug 2017, 6:55 PM
Parth Singhal
Parth Singhal - avatar
0
No, it should be if(n==0) to check whether n has value 0 or not .
3rd Dec 2016, 9:24 AM
Akshay Khandizod
Akshay Khandizod - avatar
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
3rd Dec 2016, 10:09 AM
Edwin Rybarczyk
0
n=5; if(n=0) cout<<"zero"; else cout<<"non zero "; cout<<endl; cout<<n; what should be the output?
3rd Dec 2016, 1:51 PM
Dharm Vashisth
Dharm Vashisth - avatar