這段代碼有什麼問題?誰能解釋一下?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