Home C Programming Language C Operators

C Ternary Operator

C ternary operator is a shorthand of combination of if and return statement. Syntax of ternary operator are as follows:
(expression1 ) ? expression2: expression3
If expression1 is true it returns expression2 otherwise it returns expression3. This operator is a shorthand version of this if and return statement:

	if(expression1)
		return expression2;
	else 
		return expression3;