What is the convention for the star location in reference variables?

Posted by Brett Ryan on Programmers See other posts from Programmers or by Brett Ryan
Published on 2012-11-18T04:34:04Z Indexed on 2012/11/18 5:17 UTC
Read the original article Hit count: 278

Filed under:
|
|
|

Have been learning Objective-C and 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

Personally I prefer the first option as it illustrates that x is a "pointer type of MyType".

I see the first two used interchangeably, and sometimes in the same code I've seen differing uses of both. I want to know what is the most common convention

It's been a very long time since I've programmed in C (15 years) so I can't remember if all variants are legal for C also or if this is Objective-C specific.

I'd prefer answers which state why one is better than the other, as how I explained how I read it above.

© Programmers or respective owner

Related posts about c

    Related posts about naming