为什么在 C 中声明一个只包含数组的结构?
问题描述:
我遇到了一些包含以下内容的代码:
I came across some code containing the following:
struct ABC {
unsigned long array[MAX];
} abc;
什么时候使用这样的声明才有意义?
When does it make sense to use a declaration like this?
答
它允许您将数组按值传递给函数,或从函数中按值返回.
It allows you to pass the array to a function by value, or get it returned by value from a function.
结构可以按值传递,这与在这些上下文中衰减为指针的数组不同.
Structs can be passed by value, unlike arrays which decay to a pointer in these contexts.