Choose the correct syntax for Ternary Operator?Optionscondition : expression1 ? expression2condition ? expression1 : expression2condition : expression1 : expression2condition ? expression1 ? expression2
Question
Choose the correct syntax for Ternary Operator?Optionscondition : expression1 ? expression2condition ? expression1 : expression2condition : expression1 : expression2condition ? expression1 ? expression2
Solution
The correct syntax for Ternary Operator is: condition ? expression1 : expression2
Similar Questions
Understanding Ternary operatorC language provides an operator to evaluate conditions. It is called a conditional operator (?:) or a ternary operator.Ternary operator needs exactly three operands to compute the result.The syntax for using a ternary operator is:condition? expression1 : expression2The condition should always evaluate to 1 (true) or 0 (false). If the condition evaluates to true, then expression1 is evaluated and its value is returned, otherwise expression2 is evaluated and its value is returned.Given below is an example demonstrating the usage of a conditional operator:int marks = 75, pass_marks = 50;(marks > pass_marks) ? printf("Passed C Certification") : printf("Failed C Certification"); Since the condition marks > pass_marks evaluates to true, the expression1 containing the printf statement in the above example prints "Passed C Certification"Click on Live Demo to understand the working of a ternary operator.Read the code given below and choose the correct option.#include void main() { int age = 12 , eligibility = 18; (age < eligibility) ? printf("Not eligible for voting\n") : printf("Eligible for voting\n");}OptionsEligible for votingNot eligible for votingcompilation errorNone of the above
Select the correct answerWhat will be the output of this nested ternary operator?int x = 5, y = 10;System.out.println(x > y ? "A" : (x < y ? "B" : "C"));OptionsCBACompilation error
Write a short note on Ternary Operatorwith an illustration
Which of the following is ternary operator?a.Intersectionb.Selectc.Uniond.None of these
Select the correct answerWhat is the type of expression from the given in which operator succeeds its operands is?OptionsPostfix ExpressionPrefix ExpressionBoth Prefix and Postfix ExpressionsInfix Expression
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.