Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have been learning Objective-C, noting that different books and examples use differing conventions for the location of the star (*) when naming reference variables:

MyType* x;
MyType *y;
MyType*z; // this also works

I see the first two used interchangeably, and sometimes in the same code I've seen differing uses of both. Is one format easier to read, easier to maintain, or less error prone than the other formats, or is it simply a matter of personal preference?

share|improve this question
I hardly see why this is "not constructive". Given the answer provided by dukeofgaming it is now clear to me there is a real reason why this is relevant. That being said the FAQ states that subjective questions are allowed. – Brett Ryan Nov 18 '12 at 14:03
It is also not as accepted an answer as you seem to thing. But closing this question has stopped discussion on the subject. That is also what the admins want they do not want discussion like question as there is not real answer just a bunch of people with opinions. – Loki Astari Nov 18 '12 at 15:46
The first version MyType* x; is more C++ like. The second one MyType *y; is more C like. The third one is just lazy. But there is no absolute agreement. Your best bet is to use a convention and stick with it. If the source is already one way then stick with the already established convention of the file. – Loki Astari Nov 18 '12 at 15:49
You forgot MyType * a, which I like the most. – mouviciel Dec 12 '12 at 10:38
up vote 7 down vote accepted

In my opinion this is more semantically clear:

MyType *x;

Since you can also have this without changing the convention:

MyType *x, *y, *z;

Also, I generally look at the variable declaration, not the type, when it comes to pointers.

share|improve this answer
Ah, I think I understand. So for MyType* x, y, z only x is declared as a pointer type? – Brett Ryan Nov 18 '12 at 4:46
@BrettRyan: That argument is used a lot as a reason. But most coding standards also say that declaring variables that way is also band because of this corner case. So it becomes a null argument in my mind. Personally I think it is more clear the other way with the star beside the type (as to me a C++ programmer it is part of the type). And this is were the arguments break down as C++ programs tend to fall one way while C programers the other. But on both sides there is not a universal agreement. – Loki Astari Nov 18 '12 at 15:43
@LokiAstari I really don't think it is a corner case, more like a misinterpreting of the grammar. I'm a C++ programmer more than a C programmer and I don't think that has anything to do. – dukeofgaming Nov 18 '12 at 16:51
I am fine that some people like it one and other people the other way. In the end it boils down to the same things thus making no difference. BUT your argument for is a invalid. Because that situation does not occur in real code because it is explicitly banned by coding standards (or happens so really that that when it does happen you get laughed at by experience programmers during code review and don't do it again. :-) You are more of php programmer than either. – Loki Astari Nov 18 '12 at 19:20
I don't see how my argument is invalid, not all people respect coding standards, or have coding standards at all, or have coding standards that cover this specific case, or practice code reviews. You would be surprised about what happens in very real code, specially with big distributed teams. – dukeofgaming Nov 19 '12 at 3:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.