Dark Horse Programmer---iOS learning log 9

Source: Internet
Author: User

------<a href= "http://www.itheima.com" target= "blank" >java training, Android training, iOS training,. NET training </a>, look forward to communicating with you! -------

Trinocular operator

The trinocular operator (the conditional operator) is? And:, he is a three-mesh operator, which is the amount of three operands involved in the operation.

The general form of a conditional operator consisting of a conditional expression is:

Expression 1? Expression 2: Expression 3

Evaluation rules

If the value of expression 1 is true, the value of expression 2 is used as the value of the conditional expression

Otherwise, the value of expression 2 is used as the value of the entire conditional expression.

Conditional expressions are typically used in the center of an assignment statement.

For example, a conditional statement:

if (a>b) max = A;

else max = b;

You can use conditional expressions to write: max= (a>b)? A:B;

The semantics for executing the statement are: If A>b is true, assign a to Max, or assign B to max.

Program Examples:

#include <stdio.h>

int main (int argc, const char*argv[]) {

int a = 3; b = 4; result = 0;

result = a>b?10:100;

printf ("Result =%d\n", result);

return 0;

}

Precautions

1. The operator precedence of the conditional operator is lower than the relational and arithmetic operators.

2. Conditional operators? And: is a pair of operators that cannot be disassembled for use alone.

3. The binding direction of the conditional operator is from right to left.

Dark Horse Programmer---iOS learning log 9

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.