gpt4 book ai didi

c - 数组初始化

转载 作者:太空宇宙 更新时间:2023-11-04 06:39:29 27 4
gpt4 key购买 nike

我在 Linux 中遇到了这个代码结构并且想理解它

struct mystruct {
int x;
int b[40];
};


/*later */

static struct mystruct e = { .x = 5,
.b = {-1},
};

.b = {-1} 是做什么的?它只初始化数组 b 的第一个或所有元素吗?它是如何工作的?

最佳答案

static struct mystruct e = {
.x = 5,
.b = {-1},
};

在这里它将 b[0] 初始化为 -1。其他元素初始化为0。

关于c - 数组初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10516200/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com