void sizeof_test2();
void sizeof_test2()
{
int array[5];
size_t arr_size = sizeof(array);
printf("sizeof:\n"
"array = %d\n"
"arr_size = %d\n", sizeof(array), sizeof(arr_size));
}
GCC編譯器輸出:問題理解爲size_t類型和sizeof操作符
sizeof_test2.c: In function `sizeof_test2':
sizeof_test2.c:6: error: `size_t' undeclared (first use in this function)
sizeof_test2.c:6: error: (Each undeclared identifier is<br>
reported only once sizeof_test2.c:6: error: for each function it<br>
appears in.) sizeof_test2.c:6: error: parse error before "arr_size"<br>
sizeof_test2.c:10: error: `arr_size' undeclared (first use in this<br>
function) make[2]: [build/Debug/Cygwin-Windows/sizeof_test2.o]<br>
Error 1 make[1]: [.build-conf] Error 2<br>
不知道爲什麼我得到這個錯誤,什麼是通過printf
顯示爲size_t類型的正確方法是什麼?
'size_t'在'stdlib.h'定義的(我認爲),因爲你得到未聲明的錯誤。 – slugonamission
添加了:#include 問題得到了解決..應該想到的是,我沒有通過NetBeans導航到頭,但沒有想到實際包括它..謝謝。 –
就是這樣。 'stdlib.h'把它引入我認爲,因此我迷惑。 – slugonamission