1.

Compare if else and conditional operator?

Answer»

We can use conditional operator as an alternative of if-else statement. The conditional operator is a ternary operator. 

The syntax of if-else

if (expression 1)

expression 2;

else

expression 3;

First expression 1 is evaluated if it is true

expression 2 will be executed otherwise

expression 3 will be executed. Instead of this,

we can be written as follows using conditional operator Expression 1? expression 2: expressions;



Discussion

No Comment Found