2015-10-26 Logical operator Usage Analysis

Source: Internet
Author: User

First, let's look at a piece of code:

1#include <stdio.h>2 3 intMain ()4 {5     inti =0;6     intj =0;7     8     if(++i >0|| ++j >0 )9     {Tenprintf"%d\n", i); Oneprintf"%d\n", j); A     } -      -     return 0; the}

What should be the result of the code running?
Here we should note that a rule in a logical operation is called a short-circuit rule.

In logic or operations, such as if (a| | b), as long as A is true, B will not be counted.

In logic and operations, such as if (A&&B), as long as a is false, B will not be computed.

After knowing this rule, the above code is easy to get results, I =1, j = 0;

2015-10-26 Logical operator Usage Analysis

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.