gpt4 book ai didi

c - 为什么 #define 在 for 循环中不起作用?

转载 作者:太空狗 更新时间:2023-10-29 15:28:58 25 4
gpt4 key购买 nike

<分区>

在这个程序中 TOTAL_ELEMENTS不在 for 循环中使用时可以正确计算。第一个 printf 打印正确。但是为什么即使循环中的条件为真,第二个 printf 也不起作用。 TOTAL_ELEMENTS返回 7 .和 -1<7-2-1<5是真的。那么这里有什么问题呢?

#include<stdio.h>

#define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))
int array[] = {23,34,12,17,204,99,16};

int main()
{
int d;
printf("Total= %d\n", TOTAL_ELEMENTS);
for(d=-1;d <= (TOTAL_ELEMENTS-2);d++)
printf("%d\n",array[d+1]);
return 0;
}

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