我发现这个代码在一本书:C++为什么括号?
#include <iostream>
using namespace std;
void ChangesAreGood(int *myparam) {
(*myparam) += 10;
cout << "Inside the function:" << endl;
cout << (*myparam) << endl;
}
int main() {
int mynumber = 30;
cout << "Before the function:" << endl;
cout << mynumber << endl;
ChangesAreGood(&mynumber);
cout << "After the function:" << endl;
cout << mynumber << endl;
return 0;
}
它说:
(*myparam) += 10;
什么差异将下面的产品?
*myparam += 10;
“除了可读性之外没有区别” - 是的,没有*括号的可读性更好。 – 2013-02-09 19:23:29
有一个思想流派(看起来很(流行)(某个())(())(())(())(())(())((声明))模糊的优先顺序(规则)使得),并且((()))括号更多的代码更具可读性。)(这样的人是(((((()))))))。 – 2013-02-09 19:34:38
谢谢,它似乎并不是必要的,但指针可能会非常棘手,所以我想确定一下。 – 2013-02-09 19:54:19