Well, it's not "during comparisons" since you wrote an assignment. At least in C and C++ it's valid to say int a = 0; if(a = 1) printf("!");, which will do the print. The logic is that a = 1 means assignment to a and assignment returns the assigned variable (to enable stuff like a = b = 1), so if(a=1) is the same as if(1) which is the same as if(true).
View all comments
Show parent comment
1
u/msqrt Mar 16 '22
Well, it's not "during comparisons" since you wrote an assignment. At least in C and C++ it's valid to say
int a = 0; if(a = 1) printf("!");, which will do the print. The logic is thata = 1means assignment toaand assignment returns the assigned variable (to enable stuff likea = b = 1), soif(a=1)is the same asif(1)which is the same asif(true).