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 关注
- 753 浏览
添加回答
举报