0

is there difference between char* pt and char *pt in c++?

type* pt or type *pt?

as titled, Thanks in advance.

jiafu
  • 6,338
  • 12
  • 49
  • 73
  • 2
    There is no difference between the two. The positioning of the `*` is a stylistic thing. Though be careful as it can be confusing if you declare multiple variables on the same line (which is generally poor coding style in and of itself). – aroth May 07 '13 at 02:01
  • 2
    Personal preference. The first better conveys the concept that `char*` is the type of `pt`, but the second is preferred by some because of the arcane rules when declaring multiple variables of the same type -- when you want to declare both x and y as `char*` you have to do it `char *x, *y;` (ie, `*` twice) and the second form reenforces this. – Hot Licks May 07 '13 at 02:05
  • This has been asked many times before: http://stackoverflow.com/questions/558474/what-makes-more-sense-char-string-or-char-string http://stackoverflow.com/questions/2660633/declaring-pointers-asterisk-on-the-left-or-right-of-the-space-between-the-type 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 etc. – Adam Rosenfield May 07 '13 at 02:07

2 Answers2

4

No but be careful of something like char* a, b; only a is a pointer in this statement.

smitec
  • 3,049
  • 1
  • 16
  • 12
-1

They have no functional difference.

user2350774
  • 93
  • 1
  • 5