Conditional Operator

C Programming-ல் ?: இது ternary operator ஆகும். இதையே conditional operator என்றும் அழைக்கபடுகிறது. இதில் 3 arguments கொடுக்கபடுகிறது.

Syntax

(condition) ? expression 1 : expression 2

Condition true-ஆகா இருந்தால் output expression 1-ஐ எடுத்துகொள்ளும், false-ஆகா இருந்தால் output expression 2-ஐ எடுத்துகொள்ளும்

Example for Conditional Operator

#include<stdio.h>
#include<conio.h>
void main(){
  int apple=120, grape=90;
  int apple_juice=40, grape_juice=30;
  int y;

  y=(apple>=grape)? apple_juice : grape_juice;
  printf("Juice price is Rs.%d",y);

return 0;
}

Output:

Juice price is Rs.40

Comments