2013-05-07 97 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;只有一個是在這個聲明中的指針。