Order of Operations

Source: Internet
Author: User
Tags case statement

Have the following procedures

#include <stdio.h>Main () {intA=1, b=2, c=3, d=0;if(a==1&& b++==2)if(b!=2|| c--! =3) printf ("%d,%d,%d\n", a,b,c);Elseprintf"%d,%d,%d\n", a,b,c);Elseprintf"%d,%d,%d\n", a,b,c);}


The output after the program runs is 1 3 3

Else is always paired with the nearest if, so enter the first if statement in the conditional judgment, because it is the logic and operation need to both sides of the operand value is not 0 value, it is true, so need to execute the result is 1, no longer perform the operation in the second case statement? Instead, enter the second if statement condition to judge , because the b!=2 condition is true, the value of the entire conditional expression is real, so the value of the second operand (c--! =3) of c is no longer executed, and the first else statement is no longer executed? Print the value of a 1,b value of 3,c 3?

Order of Operations

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.