我測試使用在C/C sizeof操作++的與此代碼:奇怪的情況下,同時使用的sizeof()運算用C
#include <ctype.h> /* Character types */
#include <stdio.h> /* Standard buffered input/output */
#include <stdlib.h> /* Standard library functions */
#include <string.h> /* String operations */
#include <sys/types.h> /* Data types */
#include <sys/wait.h> /* Declarations for waiting */
#include <unistd.h>
void main()
{
char a[100];
char *des = malloc(100*sizeof(char));
strcpy(des,"abcded\0");
printf("%d\n",sizeof(des));
printf("%d\n",sizeof(a));
free(des);
}
爲什麼該程序輸出:
4
100
而不是:
100
100
因爲您還沒有閱讀[comp.lang.c faq](http://c-faq.com/)...從第6節開始:) – pmg
它是'int main'; C不是Java。 – Jens
@Jens人早在Java出現之前就已經錯誤地將'main'輸入爲'void'。這是錯誤的,但沒有理由提及Java,真的。 – amalloy