The position of the * relative to the variable name doesn't matter to the compiler. Some prefer to put the * with the variable, though, because it avoids possible confusion when declaring multiple variables:
char* a, b; // a is char* and b is char, but both look like char*
char *a, b; // looks a little more like the truth: a is char*, b is char
However you always refer to objects in Objective-C via pointers, so you'd never do something like the first line below:
NSString *a, b; // WRONG: a is a pointer to an NSString object, b is just wrong.
NSString *a, *b; // OK: both a and b are pointers to NSString objects
The position of const
, on the other hand, does make a difference:
int * const a; // a points to an int, and a can't be modified to point to some other int
int const * a; // a points to an int, and that int can't be changed
Now, const
doesn't make a lot of sense with respect to objects. For one thing, NSString represents an immutable string, so declaring one const
doesn't add much. For another, one generally modifies an object in Objective-C by sending a message, not by changing the object's ivars directly, and I don't believe the compiler will prevent changes made via messages. Therefore, a const
pointer makes sense, a pointer to a const
object, not so much:
NSString * const BLANK_SPACE = @" "; // makes sense; pointer BLANK_SPACE can't change
NSString const * BLANK_SPACE = @" "; // not useful