我發現這個代碼在一本書: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