October 11th, 2002, 10:38 AM
What is this?
Where can I find documentation for the folllowing code. I know all about argv and argc. What is the "(x) ? x : x" part?
(i < argc-1) ? " " : ""
I've also seen integers used in place the chars as well.
October 11th, 2002, 10:58 AM
It's a conditional expression.
expr1 ? expr2 : expr3
expression expr1 is evaluated first. If it's true then expr2 is evaluated and if it's not then expr3 is evaluated.
October 11th, 2002, 11:12 AM
So its short hand for an if..else basically.
October 11th, 2002, 01:15 PM
Well, sort of. But an if-else construct is a statement, whereas the ternary ?: operator results in an expression. Example:
a = (x < y) ? x : y;
So yes, it's like an if-else statement in the sense that there's a conditional expression involved, but that's about it.
"A poor programmer is he who blames his tools."