易错题之前置++后置++

#include<iostream>
using namespace std;
int main()
{
	int m = 5;
	if (m++ > 5)
	{
		cout << m << endl;
	}
	else
		cout << --m;//5
	system("pause");
}
//由此又即兴忆起金山的一道笔试题
#include<iostream>
using namespace std;
int main(int args,char **argv)
{
	if (!(cout<<"hello "))//这是有些取巧的办法
	{
		cout << "hello ";
	}
	if (args == 0 || main(0, NULL))
	{
		cout << "hello ";
	}
	else
	{
		cout << "world" << endl;
		system("pause");
	}
	return 0;
}
/*
	1.第一次执行main方法是args=1.第二次调用main传入NULL,这样args==0,就是true。
	2.利用||运算符,如果前面为true则不在计算后面的表达式,所以就控制了main方法
	只调用一次。
*/

posted @ 2017-03-14 21:23  乐天的java  阅读(50)  评论(0)    收藏  举报