Syntax Differences when instantiating


Loving the book so far, and happened across another way to declare a variable.

// asterisk next to NSString
NSString* string = [_characterCount objectValue];

// asterisk next to variable 
NSString *string = [_characterCount objectValue];

Anybody know if there is a difference? Both compile and run as you would expect.


There’s no functional difference between the two; it’s only a matter of style. Some people like to put the asterisk next to the type (or class) name, and some people like to put it next to the variable name. Some people put a space on both sides of the asterisk. :slight_smile: The reasoning I’ve heard used for putting the asterisk next to the type name is because the asterisk is part of the variable type (a pointer to the given type). In my opinion it’s so common to use the asterisk that this sort of clarity is unnecessary.