(age >= 18)
is false therefore, <false-expression> gets executed.Saturday, July 11, 2020
Conditional or ternary operator in C
Conditional or ternary (?:) operator in C
The ternary operator (?:) is also known as conditional operator. It is a replacement of if..else statements. Which is used to evaluate an expression based on condition in place of longer if...else conditional statements.
Syntax for ternary operator:
1) The ternary operator takes three arguments as you can see above.
2) Syntax of ternary operator is always be like <conditional-expression> followed by ? symbol then <true-expression> followed by :
symbol and then at last <false-expression>
3) If the condition is true then <true-expression> is executed else <false-expression> is executed. Let's have a look at the below example to uderstand it better way.
Example 1: Ternary operator (?:)
Output:
In the above program prints You are not adult.Since the condition
Example 2: Ternary operator (?:)
Output:
Next topic >> to be updated soon.
Help others by sharing this page.
Ahmad Irshad
Author & Editor
I love blogging, teaching, learning computer science and sharing it to others. I've written and develped this site so that students may learn computer science related tutorials eaisly. MCA / MCITP
Saturday, July 11, 2020
C
Subscribe to:
Post Comments (Atom)
0 Comments:
Post a Comment
Please don't enter any spam link in the comment box.