Knowee
Questions
Features
Study Tools

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

Question

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

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Not eligible for voting

Similar Questions

Choose the correct syntax for Ternary Operator?Optionscondition : expression1 ? expression2condition ? expression1 : expression2condition : expression1 : expression2condition ? expression1 ? expression2

Write a short note on Ternary Operatorwith an illustration

Mr. Liam is an aspiring programmer exploring the use of logical operators. Create a simple program to assist Liam in understanding logical operations. Prompt two integers, a and b, and use logical operators to determine whether both values are non-zero. Display 'True' if both values are non-zero; otherwise, display 'False'.Input format :The input consists of two space-separated integers, representing a and b.Output format :The output displays "True" if both a and b are non-zero; otherwise, display "False".Refer to the sample output for formatting specifications.Code constraints :In the given scenario, the test cases fall under the following constraints:0 ≤ a, b ≤ 1000

Understanding Ternary operator#include <stdio.h>int main() { int k, num = 100; k = (num > 50 ? (num <= 10 ? 100 : 200): 500); printf("%d %d\n", num, k); return 0;}What are the values a =

Consider the code below. What is the output?public class TernaryOperator { public static void main(String[] args) { int x = 30; int y = 50; String result = (x > y) ? "x is greater" : "y is greater"; System.out.println(result); }}a)"x > y"b)"y is greater"c)Compilation errord)"x is greater"

1/4

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.