C/C++运算优先级 ++和()

int main() {
	Solution sol;

	int i = 0;
	if (++i) { // 预自增,先自增,再括号
		cout << "Right" << endl; // 输出Right
		cout << i << endl; // i=1
	} 
	else {
		cout << "Wrong" << endl;
		cout << i << endl;
	}


	return 0;
}
int main() {
	Solution sol;

	int i = 0;
	if (i++) { // 后自增,先括号,再自增
		cout << "Right" << endl;
		cout << i << endl;
	}
	else {
		cout << "Wrong" << endl; // 输出Wrong
		cout << i << endl; // i=1
	}


	return 0;
}

 

你可能感兴趣的:(C++)