Posts

Showing posts from April, 2025

Ternary operator and Nested Ternary operator

Ternary operator  Ternary operator which is a conditional operator and, as the name suggests, it takes three operands (parts). Ternary operator is available in most languages, like, C, C++, Java, JavaScript, etc  Syntax:-  variable = condition ? expression1_if_true : expression2_if_false Explanation: condition: This is a boolean expression that evaluates to either true or false. expression1_if_true: This is the value or statement that is executed if the condition is true. expression2_if_false: This is the value or statement that is executed if the condition is false.  Ternary operator is nothing, just a concise way of writing an if-else statement, i.e. the same operation can be achieved using an if-else block as shown below.  if(condition){     variable = value_if_true  }else{     variable = value_if_false  } Example 1 :- C program find max number among two given numbers using ternary operator #include <stdio.h> int mai...