What is conditional operators ? Using conditional operator find a smallest number amongst two numbers ?

Conditional operator is also called ternary operator and they are ? and :
Quetion mark and Collon.


int Num1,Num2;
int MinNum = Num1 < Num2 ? Num1 : Num2;
Cout << MinNum;

It Will give min number from two numbers num1 and num2;

Adding to crazyboy:

It can be generalized as follows:

expr?expr1:expr2;

MEANS

if(expr)
        expr1;
else
        expr2;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.