C Language Learning Notes (III.)--conditional expression

Source: Internet
Author: User

Conditional expression:

Expression 1-expression 2: Expression 3

(1) The order in which the conditional expression is executed: first, the expression 1 is solved, if it is not 0 (true), the expression 2 is evaluated, and the value of the expression 2 is the value of the entire expression. If the value of expression 1 is 0 (false), the expression 3 is solved, and the value of expression 3 is the value of the entire conditional expression.

(2) The conditional expression takes precedence over the assignment operator, max= (a>b)? A:B first solves the conditional expression in the assignment to Max.

(3) The binding direction of the conditional expression is "from right to left" such as: A>b? A:c>d? C:d supposed to be a>b? A: (c>d?) C:D)

(4) The conditional expression can also be written in the following form: A>b? (a=100): (b=100) expression 2 and expression 3 can be not only a numeric expression, but also an assignment expression or a function expression.

(5) In a conditional expression, the type of expression 1 can be different from the type of expression 2 and expression 3, such as: X. ' A ': ' B ' x is an integer variable, if x equals 0 The value of the expression is ' B '. The type of expression 2 and expression 3 can also be different, when the type of the conditional expression is the higher type. such as: X>y. 1:1.5 if x<=y, then the value of the conditional expression is 1.5, if x>y, the value should be 1, because 1.5 is solid, higher than the integer type, so 1 is converted to 1.0.

(6) Example: Enter a character to determine whether it is a capital letter, if it is, convert it to lowercase letters; And then output the resulting character.

Main ()

{

Char ch;

scanf ("%c", &ch);

Ch= (ch>= ' A ' &&ch<= ' Z '). (ch+32): ch;

printf ("%c/n", ch);

}

Related Article

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.