【发布时间】:2021-11-10 02:40:22
【问题描述】:
我写了以下代码:
#include <stdio.h>
int array[] = {23, 43, 12, 17, 204, 99, 16};
#define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))
int main()
{
int test = -1;
if (test <= TOTAL_ELEMENTS)
{
printf("Hello, got here!\n");
}
}
当我编译这段代码(使用gcc main.c -Wall(没有警告!))并运行它时,printf 无法执行。我的意思是,test = -1,这绝对小于数组的大小(7 位)。错误在哪里?
【问题讨论】:
-
试试
long long test = -1;
标签: c if-statement testcase