Tutorials Point


  Learning C
  C Function References
  C Useful Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     About TP     Advertising  
Latest C Tutorial

ternary operator examples:

previous

Try following example to understand ternary operator. You can put the following code into a test.c file and then compile it and then run it .

#include <stdio.h>

main()
{
   int a , b;

   a = 10;
   printf( "Value of b is %d\n", (a == 1) ? 20: 30 );

   printf( "Value of b is %d\n", (a == 10) ? 20: 30 );
}

This will produce following result:

Value of b is 30
Value of b is 20


previous Printer Friendly

Advertisements


  

Advertisements