3 回答

TA貢獻(xiàn)1875條經(jīng)驗(yàn) 獲得超3個(gè)贊
我個(gè)人更喜歡*將其余類型的
char* p; // p is a pointer to a char.
人們會(huì)爭(zhēng)辯“但隨后char* p, q;會(huì)產(chǎn)生誤導(dǎo)”,我對(duì)此表示“不要這樣做”。

TA貢獻(xiàn)1963條經(jīng)驗(yàn) 獲得超6個(gè)贊
怎么寫沒有區(qū)別。但是,如果您想在一行中聲明兩個(gè)或多個(gè)指針,最好使用(b)變體,因?yàn)楹芮宄胍裁?。往下看?/p>
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 關(guān)注
- 778 瀏覽
添加回答
舉報(bào)