In C, x=50 would set the variable x to 50.nyarla wrote:hairy_pete wrote:Hence the coding rule that such equation is to be written with the constant on the left side,Code: Select all
if (x = 50) some_code(); else some_other_code();so that it doesn't compile when you writeCode: Select all
if (50==x) blah(); else blurb();Code: Select all
if (50=x)
this may be a dumb question...but what's this one all about? i only vaguely know C (i've been trying to mess around with it again recently...). could someone explain this to me? like..what's the difference between "if (x=50)" and "if (50==x)" (or "if (50=x)") ..or am i missing the point entirely?
To compare values in C you need to use ==
So 50==x would compile as it's a valid comparison, but 50=x would fail as you're trying to set a variable called "50" to the value x.
Muttley






