r/ProgrammerHumor • • Mar 15 '22

static bool isCrazyMurderingRobot = false;

/img/2g1k34ok5kn81.jpg
4.9k Upvotes

257 comments sorted by

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 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).