Solution Order of binary operator && and unary operator + +

Source: Internet
Author: User
 
Test0911a.cpp:Defines the entry point for the console application.

#include "stdafx.h" #include <iostream> using namespace std;

	int main (int argc, char* argv[]) {printf ("--------------> Hello world!\n");

	int a = 0; if (a++ && a) cout<< "a++ && A is true, a =" <<a<<endl; There is no output else cout<< "a++ && A is false, a =" <<a<<endl;//output, and a = 1;
    When judging (a++) First use a (value of 0) to judge as false, and then do not continue the int b = 0; if (b++) cout<< "b++ is true, B =" <<b<<endl; There is no output else cout<< "b++ is false, B =" <<b<<endl;
	Output, and b = 1 int c=1; if (--c) cout<< "--c true, c=" <<c<<endl; There is no output else cout<< "--c is False, c=" <<c<<endl;//output, and c=0;
	Judgment (--C) is to do a minus 1 calculation, in the use of C value (0) to determine the int d=0;  if (++d) cout<< "++d true, d=" <<d<<endl;
	output, and d=1; else cout<< "++d is False, d=" <<d<<endl;
	no output int e=0; if (++e && e) cout<< "++e && E is true, e=" <<e<<endl; Output, and E =1 else cout<< "++e && E is false, e=" <<e<<endl;
No output return 0;

 }


Ps:

Similar to C + + Primer (Fourth edition) Exercise solution, Page 61, Exercise 5.29

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.