This question already has answers here:
Closed 5 years ago.
Why is the asterisk before the variable name, rather than after the type?
(13个答案)
char* myStringchar *myString是否被视为最佳实践?我的教授总是使用char* myString,这看起来不像char *myString,但我也看到许多开发人员将*与字符串放在一起

最佳答案

有些人更喜欢char *myString,因为指针不是“分布式的”。即:

char* str1, str2;

// Is equivalent to:
char* str1; // or char *str1;
char str2;  // Note, not a pointer

通过这样定义:
char *str1, str2;

更清楚的是,一个是指针,一个不是。另外请注意,一些编码风格的指导原则不鼓励在同一行声明多个变量,因此这并不重要,在这种情况下(我相信)char* str;更具可读性。

关于c - 带有typedef或var名称的星号,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22947306/

10-11 22:13
查看更多