这段代码有什么问题?谁能解释一下?c代码输出意外/预期行为
#include <stdio.h>
#include <malloc.h>
#define TOTAL_ELEMENTS (sizeof(array)/sizeof(array[0]))
int array[] = {23,34,12,17,204,99,16};
int main()
{
int num;
int d;
int size = TOTAL_ELEMENTS -2;
printf("%d\n",(TOTAL_ELEMENTS-2));
for(d=-1;d <= (TOTAL_ELEMENTS-2);d++)
printf("%d\n",array[d+1]);
return 0;
}
当我打印它给5,但里面for循环发生了什么?
完美的解释... :-) – peeyush
2s补码是无效的 - '(size_t)-1'总是'SIZE_MAX'。 – caf