Skip to main content

example of CONDITIONAL OR TERNARY OPERATORS IN C

/* 1.Conditional operators return one value if condition is true and returns another value is condition is false.
This operator is also called as ternary operator.
Syntax     :        (Condition? true_value: false_value);
Example :         (A > 100  ?  0  :  1);
2.In above example, if A is greater than 100, 0 is returned else 1 is returned. This is equal to if else conditional statements.
*/
#include <stdio.h>
 
int main()
{
   int x=1y ;
   y = ( x ==1 ? 2 : 0 ) ;
   printf("x value is %d\n"x);
   printf("y value is %d"y);
}
/* output
x value is 1
y value is 2
*/

Comments

Popular posts from this blog

example of typecasting in c

/*Type Casting in C Typecasting allows us to convert one data type into other. */ //simple example to cast int value into the float. #include <stdio.h>    int   main (){   float   f = ( float ) 9 / 4 ;     printf ( "f : %f \n " ,  f  );     return   0 ;   }