Conditional Operator




  • Given that A, B, C are expressions; then the expression
                A ? B : C

  • has as its value B if A is nonzero, and C otherwise; only expression B or C is evaluated
  • In order to generate 1 or 0 for A, it should be a relational or logical expression.
  • Expressions B and C must be of the same data type
  • If they are not, but are both arithmetic data types, the usual arithmetic conversions are applied to make their types the same
  • If one is a pointer and the other is zero, the latter is taken as a null pointer of the same type as the former.
  • If one is a pointer to void and the other is a pointer to another type, the latter is converted to a pointer to void, and that is the resulting type.
Example: 






Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.