3 回答

TA貢獻1875條經驗 獲得超3個贊
我個人更喜歡*將其余類型的
char* p; // p is a pointer to a char.
人們會爭辯“但隨后char* p, q;會產生誤導”,我對此表示“不要這樣做”。

TA貢獻1963條經驗 獲得超6個贊
怎么寫沒有區別。但是,如果您想在一行中聲明兩個或多個指針,最好使用(b)變體,因為很清楚您想要什么。往下看:
int *a;
int* b; // All is OK. `a` is pointer to int ant `b` is pointer to int
char *c, *d; // We declare two pointers to char. And we clearly see it.
char* e, f; // We declare pointer `e` and variable `f` of char type.
// Maybe here it is mistake, maybe not.
// Better way of course is use typedef:
typedef char* PCHAR;
PCHAR g, h; // Now `g` and `h` both are pointers.
// If we used define construction for PCHAR we'd get into problem too.
- 3 回答
- 0 關注
- 792 瀏覽
添加回答
舉報