// 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 为真, a ="<<a<<endl; // 没有输出
else
cout<<"a++ && a 为假, a ="<<a<<endl;//输出,且a =1; 判断(a++)时候先用a(值为0) 判断为假,后面就不要继续了
int b =0;
if( b++ )
cout<<"b++ 为真,b = "<<b<<endl; // 没有输出
else
cout<<"b++ 为假,b = "<<b<<endl; // 输出,且b = 1
int c=1;
if(--c)
cout<<"--c 为真,c= "<<c<<endl; // 没有输出
else
cout<<"--c 为假,c= "<<c<<endl;// 输出,且C=0; 判断(--c)是先做了减1 计算,在用c值(0)来判断
int d=0;
if(++d)
cout<<"++d 为真,d= "<<d<<endl; // 输出,且d=1;
else
cout<<"++d 为假,d= "<<d<<endl; // 没有输出
int e=0;
if(++e && e)
cout<<"++e && e 为真,e= "<<e<<endl; //输出,且e =1
else
cout<<"++e && e 为假,e= "<<e<<endl; //没有输出
return 0;
}
PS:
类似 C++ Primer( 第四版) 习题解答, Page 61,习题5.29