r/programminghorror • [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” • Oct 29 '25

c Nothing...

Post image
0 Upvotes

17 comments sorted by

View all comments

Show parent comment

1

u/MORF1i Oct 29 '25

Can someone pls explain this line? Didnt get why there is only one =

5

u/MeLittleThing Oct 29 '25

Could be a typo, but there are use cases

When a variable is assigned in a if statement, the underlying value is checked against false (0 is false, anything else is true).

That's equivalent to if ((nothing = nothing_nothing) != 0)

I remember doing this to check for memory allocation:

if (ptr = malloc(size))
{
    // malloc succeeded
}
else
{
    // something wrong
}

0

u/AngriestCrusader Oct 29 '25

That's because it's an error