Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convention for pointer *

Out of curiosity; why is convention for pointers in C languages like this:

NSString *str = ...

Wouldn't be more appropriate to write:

NSString* str = ...

because we are defining pointer to NSString? (in Objective-C methods we do have (NSString*)parameter1 convention)

Again - I'm asking out of curiosity and to be able to better understand logic behind this... I'm not trying to reinvent the wheel or start flame war.

like image 742
nikib3ro Avatar asked Dec 02 '10 20:12

nikib3ro


1 Answers

If you declare multiple pointer variables in a single declaration, you must write

char *a, *b;

since the declaration

char* a, b;

would declare a as a char pointer, but b as a plain char. IOW, this spacing shows that the asterisk really binds to the name only where it appears.

like image 110
Martin v. Löwis Avatar answered Sep 21 '22 15:09

Martin v. Löwis