What is the ternary (?:) operator?

Are you preparing for IT certification? With practice questions, study notes, interactive quizzes, tips and technical articles, uCertify PrepKits ensure that you get a solid grasp of core technical concepts to ace your certification exam in first attempt.

What is the ternary (?:) operator?

Rating:

The ?: operator is a conditional operator that is used as a short hand for an if-else statement in some cases. It is also known as ternary operator because it takes three operands. The general form of the operator is as follows:

opr1 ? opr2: opr3

where, opr1 can be any expression that evaluates to a boolean value. Both opr2 and opr3 are required to return values of the same type. If opr1 evaluates to true, opr2 is evaluated. Otherwise, opr3 is evaluated.

The general form of the operator is equivalent to the following if-else statement:

if(opr1){
   opr2
}
else{
   opr3
}


Rating:



Other articles

Click here to Article home

 
uCertify.com | Our Company | Articles | Privacy | Security | Contact Us | News and Press Release | uCertify India
MCSE: MCSA, MCTS, MCITP    JAVA Certification: SCJP, SCWCD Cisco Certification: CCNA, CCENT, A+, Network+, Security+
Oracle Certification: OCP 9i, OCP 10g, OCA 9i, OCA 10g CIW foundation    EC-212-32    CISSP    Photoshop ACE    Adobe Flash ACE
© 2008 uCertify.com. All rights reserved. All trademarks are the property of their respective owners.