# Pointer declaration

#### Eddie

Just need to confirm that the following two ways of declaring pointers are equivalent:

Type* identifier;

Type *identifier;

They both declares a pointer called identifier of Type , right?. I came across these two kinds of declarations in different books, it used to be really confusing to me, because I got muddled of the latter version with deferencing, which use the '*' in front of the identifier. Please clarify for me. Thanks.

#### alain

##### Older and Wiser
Eddie said:
Just need to confirm that the following two ways of declaring pointers are equivalent:

Type* identifier;

Type *identifier;

They both declares a pointer called identifier of Type , right?. I came across these two kinds of declarations in different books, it used to be really confusing to me, because I got muddled of the latter version with deferencing, which use the '*' in front of the identifier. Please clarify for me. Thanks.

I think so. I always used the latter for some reason.

#### Hien

I think they're the same aren't they?

#### Uncle Max

Yes, they are absolutely the same.

#### DominiConnor

Agree with the above, but what you might have read is one of the following

TYPE *p, q;
Defines p to be a pointer, but q isn't

However a typedef would get them both.

#### ExSan

at compiler time blanks are eliminated, token Type is identified in advance, so it makes no difference

#### DominiConnor

For whatever reason I find Type *p to be more readable, I guess because it is more common.

#### Polter

http://www2.research.att.com/~bs/bs_faq2.html#whitespace
The choice between int* p;'' and int *p;'' is not about right and wrong, but about style and emphasis. C emphasized expressions; declarations were often considered little more than a necessary evil. C++, on the other hand, has a heavy emphasis on types.
A typical C programmer'' writes int *p;'' and explains it *p is what is the int'' emphasizing syntax, and may point to the C (and C++) declaration grammar to argue for the correctness of the style. Indeed, the * binds to the name p in the grammar.
A typical C++ programmer'' writes int* p;'' and explains it p is a pointer to an int'' emphasizing type. Indeed the type of p is int*. I clearly prefer that emphasis and see it as important for using the more advanced parts of C++ well.

#### quantstart

Coming from a C++ background (i.e. not specifically C), I always prefer the former approach. As Polter says, it puts emphasis on the type.

Replies
0
Views
6K
Replies
0
Views
1K
Replies
0
Views
6K
Replies
2
Views
4K
Replies
2
Views
6K