“char (*a)[12]”是什么意思?意思是?
这是来自C标准吗?
Is this from the C standard?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
这是来自C标准吗?
Is this from the C standard?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
如果您对 C 声明感到困惑,可以使用
cdecl
程序来解释它:If you're confused by a C declaration, you can use the
cdecl
program to explain it:因为 C 中的声明遵循运算符优先级规则(即在间接寻址之前评估数组订阅),所以您需要括号来声明指向数组类型的指针。
在许多用例中,与使用普通
char *
相比,实际上并没有任何实际好处,除了它是一种强制数组大小的方法,特别是当用作函数参数时:相当于
并接受任何
char *
,而只接受指向大小为
42
的数组的指针。由于在后一种情况下访问
bar
的元素很麻烦,因此最好在函数体中立即定义一个等效的char *
,以便您可以直接使用订阅
baz[13]
而不是(*bar)[13]
。Because declarations in C follow the operator precedence rules (ie array subscription is evaluated before indirection), you'll need parens to declare pointers to array types.
In many use cases, there's not really any practical benefit over using a plain
char *
, except that it's a way to enforce the array size, especially when used as a function parameter:is equivalent to
and accepts any
char *
, whereaswill only accept pointers to arrays of size
42
.As accessing the elements of
bar
in the latter case is cumbersome, it might be a good idea to immediately define an equivalentchar *
in the function bodyso that you can use direct subscription
baz[13]
instead of(*bar)[13]
.指向 12 个字符数组的指针。
A pointer to an array of 12 characters.
a
是一个指向12 个字符的数组
的指针。a
is a pointer pointing to anarray of 12 characters
.