开发者

Code formatting when using pointers

开发者 https://www.devze.com 2022-12-29 19:32 出处:网络
Is there any reason why the asterisk is next to the object type in this code? I\'m a little confused by the way I see this used. Some times it looks like this:

Is there any reason why the asterisk is next to the object type in this code? I'm a little confused by the way I see this used. Some times it looks like this:

NSString* stringBefore;

an开发者_运维知识库d sometimes like this:

NSString *stringBefore;

Is there a difference? Or a right or wrong way to do this?

Thanks


I use the * near the variable name and not the type, since if you declare something like:

int *i, j;

i will be a pointer to int, and j will be a int.

If you used the other syntax:

int* i, j;

you may think that both i and j are pointers when they are not.

That said, I don't use nor recommend declaring a pointer and a non-pointer variable in the same line, as in this sample.


It makes no difference.

It just just an indicator to how well versed the author is in writing and reading Objective-C. The traditional standard is to write it as:

NSString *stringBefore;


There is no difference.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号