Nothinman
Elite Member
- Sep 14, 2001
- 30,672
- 0
- 0
Assuming that "n" is some integer, and you want to print "TRUE" if it's even, and "FALSE" if it's odd:
(n % 2) ? printf("FALSE") : printf("TRUE");
I have no clue what this is actually useful for, though.
Some people find the ?: notation easier to read, but there's the little fact that the compiler will treat that exactly as an if/then/else statement.
You could make a two-element array and typecast the bool into an int. Something like this:
And that begs the question, is it better to waste the memory for the arrays or to just deal with a simple conditional?