- What is a condition expression?
- How do you write a conditional expression?
- What is a conditional expression example?
What is a condition expression?
A conditional expression is an expression you can use to select one of two values based on a Boolean condition. A conditional expression contains the conditional operators IF . . . THEN . . . ELSE and has the following format. IF Boolean-expression THEN expression1 ELSE expression2.
How do you write a conditional expression?
The syntax of a conditional expression consists of a conditional statement in parentheses. This can be just like the conditionals used in an if-else statement. This is followed by a question mark, a value to be set if the condition is true, a colon, and finally a value to be set if the condition is false.
What is a conditional expression example?
if (y > z) x = y; else x = z; The following expression calls the function printf , which receives the value of the variable c , if c evaluates to a digit. Otherwise, printf receives the character constant 'x' .