We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi folk, I have
u16 wTemp = 0; fsingle fTemp = 17.5123; wTemp = (u16)fTemp;
Good to see people who aren't afraid of the Ternary Operator!
Indeed, I always tell people who say it obfuscates code that var++; is very odd at first glance as is var += value; ?: is very, very clear once the idiom is learned just as are var++ and var += value. Long live all parts of the the C language. Example use #234 of ?:...
int cash = 1; printf("You have %d dollar%s\n", cash, 1 == cash ? "" : "s");
Of course this would have worked just as well I suppose:
int cash = 1; char dollarStr[][sizeof "dollars"] = { "dollars", "dollar" }; printf("You have %d %s\n", cash, dollarStr[cash == 1]);