The Conditional Operator


The Conditional Operator(?:)
The conditional operator in C is also known as ternary operator. It is called ternary operator because it takes three arguments. The conditional operator evaluates an expression returning a value if that expression is true and different one if the expression is evaluated as false.

#include< iostream>
using namespace std;

int main ()
{
   // Local variable declaration:
   int x, y = 10;

   x = (y < 10) ? 30 : 40;

   cout << "value of x: "<< x << endl;

  return 0;
}

Then the above code is compiled and executed, it produces the following result:
value of x: 40

Comments