指针约定* [英] Convention for pointer *

查看:115
本文介绍了指针约定*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于好奇心;为什么C语言中的指针的约定如下:




NSString * str = ...



不适合写:



$因为我们是定义指向NSString的指针?b $ b NSString * str = ...



< (在Objective-C方法中我们有(NSString *)parameter1约定)



再次 - 我出于好奇心,能够更好地理解...

解决方案

如果你在一个文件中声明多个指针变量,单一声明,必须写

  char * a,* b; 

 




char * a,b;

会将 a b 作为纯字符。 IOW,这个间距显示星号确实绑定到名称只出现在它。


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.

解决方案

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.

这篇关于指针约定*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆