Clouds
Home
Tutorial of C language
Computer Language
Introduction to C
Programming in C
Structure of C program
Variable in C
Datatypes in C
Token in C
Operator in C
Precedence of C Operator
Assignment Operator in C
Logical Operator in C
Bitwise Operator in C
Ternary Operator in C
C Input Output
Pointers in C
Storage Classes of C
Control Structure of C
C Decision Making Statement
C Looping Statement
C Jumping Statement
C Function
Function Call By Value
Function Call By Reference
C Input Output Function
C Structure
Array in C
Union in C

Ternary operator

Ternary operator(? And : ) requires three operands.
  • Syntax:- Condition ? Operand1 : Operand2
  • First of all the condition is tested and if the result is true then the value of the operand1 is taken otherwise value of operand2 is taken. For Example:
    				int minimum;
    				minimum=a<b ? a : b;
    				

    first the condition (a>b) is evaluated, if the value is true then the value of a is taken by minimum; otherwise value of b is given to the minimum Example:-
    				#include<stdio.h>
    				#include<conio.h>
    				void  main()
    				{
    					int a=1,b=2,high;
    					clrscr();
    					high=a>b ?a:b;
    					printf("Highest value=%d",high);
    					getch();
    				}
    				


    C Input Output >>
    Pointers in C >>
    Storage Classes of C >>
    Control Structure of C >>
    C Decision Making Statement >>


    Home Clouds