gpt4 book ai didi

C符号常量+结构

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

给定以下代码片段:

#include <stdio.h>
#include <stdlib.h>
#define MAX_SIZE 15

typedef struct{
int touchdowns;
int interceptions;
int tackles[MAX_SIZE + 1]; //this is the line in question
}stats;

向我提出的问题是,“为什么这条线 [如上所示] 将可能的拦截次数加 1?”

----不是为什么会想要,而是它是如何/为什么起作用的。换句话说,为什么它是有效代码,不一定是有效逻辑。 -澄清

我不确定如何详细回答这个问题。任何帮助将不胜感激。

最佳答案

正如 Armin 指出的那样,标记 MAX_SIZE 被预处理器替换了。但为了澄清,这不是它最终工作/编译的原因。编译的实际要求是,数组大小是一个常数整数表达式,它适用于相关代码。

关于C符号常量+结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15044959/

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