为什么在 C 中声明一个只包含数组的结构? [英] Why declare a struct that only contains an array in C?

查看:30
本文介绍了为什么在 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.

这篇关于为什么在 C 中声明一个只包含数组的结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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