一个很精典C程序
时间:2010-11-19 来源:1987hanen
这个程序包括很多东西,慢慢机会。
#include<stdio.h>
main()
{
char a[1000];
char b[10004];
int i;
int *p = NULL;
struct student
{
}stu;
for(i=0;i<1000;i++)
{
a[i]=-1-i;
}
printf("%d\n",strlen(a));
printf("int=%d\n",sizeof(int));
printf("short=%d\n",sizeof(short));
printf("char=%d\n",sizeof(char));
printf("long=%d\n",sizeof(long));
printf("float=%d\n",sizeof(float));
printf("double=%d\n",sizeof(double));
printf("sizeof(p)=%d\n",sizeof(p));
printf("sizeof=%d\n",sizeof(*p));
printf("sizeof(stu)=%d\n",sizeof(stu));
printf("%d\n",strlen(b));
return 0;
} 在GCC的编译结果如下: 255
int=4
short=2
char=1
long=4
float=4
double=8
sizeof(p)=4
sizeof=4
sizeof(stu)=0
0 在VC中编译sizeof(stu)=1
main()
{
char a[1000];
char b[10004];
int i;
int *p = NULL;
struct student
{
}stu;
for(i=0;i<1000;i++)
{
a[i]=-1-i;
}
printf("%d\n",strlen(a));
printf("int=%d\n",sizeof(int));
printf("short=%d\n",sizeof(short));
printf("char=%d\n",sizeof(char));
printf("long=%d\n",sizeof(long));
printf("float=%d\n",sizeof(float));
printf("double=%d\n",sizeof(double));
printf("sizeof(p)=%d\n",sizeof(p));
printf("sizeof=%d\n",sizeof(*p));
printf("sizeof(stu)=%d\n",sizeof(stu));
printf("%d\n",strlen(b));
return 0;
} 在GCC的编译结果如下: 255
int=4
short=2
char=1
long=4
float=4
double=8
sizeof(p)=4
sizeof=4
sizeof(stu)=0
0 在VC中编译sizeof(stu)=1
相关阅读 更多 +