2013-05-07 44 views
0

char * pt和char * pt在C++中有区别吗?char * pt和char * pt在C++中有区别吗?

type * pt or type * pt?

标题为,在此先感谢。

+2

这两者之间没有区别。 '*'的定位是一种文体。虽然要小心,因为如果你在同一行上声明了多个变量(这通常是糟糕的编码风格本身),可能会引起混淆。 – aroth 2013-05-07 02:01:49

+2

个人喜好。第一个更好地表达了'char *'是'pt'类型的概念,但是当声明多个相同类型的变量时,由于某些规则的原因,第二个被某些人优先选择 - 当你想声明x和y时作为'char *'你必须做'char * x,* y;'(即'*'两次),第二种形式重新强制这个。 – 2013-05-07 02:05:39

+0

这已被问了很多次之前:http://stackoverflow.com/questions/558474/what-makes-more-sense-char-string-or-char-string http://stackoverflow.com/questions/2660633/声明指针 - 星号之间的左或右空间之间的类型http://stackoverflow.com/questions/4203009/c-initialization-of-pointers-asterisk-position http://stackoverflow.com/questions/398395/in-c-why-is-the-asterisk-before-the-variable-name-rather-than-after-the-type等。 – 2013-05-07 02:07:16

回答

4

不,但要小心诸如char* a, b;只有一个是在这个声明中的指针。

相关问题