I saw some c++ syntax that puzzled me
int x = 10; if(x){ //this line confused me //code } else{ //code } i don't understand how this is valid code, what does the if(x) do?
1 Answer
An int converts implicitly to a bool. Any int that's non-zero evaluates to true. A zero integer converts to false. In your case, that line basically tests whether x is different from zero, and it is equivalent with
if(x != 0) ...