c 中 sizeof 运算符的大小是多少?
最近我参加了一次关于“SureSoft Technology”的采访……在那次采访中,他们问了一个问题,比如“c中的sizeof运算符的大小是多少?”
如果有人知道答案与我分享吗?
In recent I was attend one Interview on "SureSoft Technology"...... In that interview, they ask one question lik "What is size for the sizeof operator in c? "
If any one Know answer Share with me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
sizeof
运算符本身没有大小。它的结果通常*会在编译时变成常量值。至于它返回的值,那就是参数的大小(以字节为单位)。结果的类型是
size_t
(在
中定义)(§6.5.3.4.4)* - 动态大小自动的显着例外数组。
The
sizeof
operator itself has no size. Its result will generally* turn into a constant value at compile time.As for the value it returns, that would be the size, in bytes, of the argument. The type of the result is
size_t
(defined in<stdlib.h>
) (§6.5.3.4.4)* - with the notable exception of dynamically-sized automatic arrays.
您可以在此处和这里:sizeof的结果是size_t类型,并且:
You'll find the answers here and here: the result of sizeof is of type size_t, and:
stddef.h 中定义的类型 size_t。
The type size_t defined in stddef.h.
答案很简单 - 它是传递给 sizeof 的给定数据结构的大小(以字节为单位)。
例如:
希望有帮助。
The answer is simple - it's the size in bytes of the given data structure that you pass to sizeof.
For example:
Hope that helps.