Chinaunix首页 | 论坛 | 博客
  • 博客访问: 623619
  • 博文数量: 138
  • 博客积分: 3067
  • 博客等级: 中校
  • 技术积分: 1565
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-21 12:44
文章分类

全部博文(138)

文章存档

2016年(5)

2014年(4)

2012年(1)

2011年(2)

2010年(10)

2009年(19)

2008年(97)

我的朋友

分类: C/C++

2008-04-09 17:19:10

C/C++笔试常考题

1. sizeof

int main()
{
        char *a1 = "DFDFDF";
        char a2[] = "sdfdfsf";
        char a3[100] = "DFD";
        int* a13;
        int a4[] = {2, 3};
        int a5[100];
        void *a6;
        void *a7 = (void *) malloc(100);
        void *a8 = (char *) malloc(100);
        char *a9 = (char*) malloc(30);
        char *a10 = (char *) malloc(30);
                                                  
        struct a11{
                short s1;
                short s2;
                short s3;
                int s4;
        };
        struct a12 {
                short s1;
                long s3;
        };
                                                  
        printf("SIZE OF A1:%d\n", sizeof(a1));
        printf("SIZE OF A2:%d\n", sizeof(a2));
        printf("SIZE OF A3:%d\n", sizeof(a3));
        printf("SIZE OF A4:%d\n", sizeof(a4));
        printf("SIZE OF A5:%d\n", sizeof(a5));
        printf("SIZE OF A6:%d\n", sizeof(a6));
        printf("SIZE OF A7:%d\n", sizeof(a7));
        printf("SIZE OF A8:%d\n", sizeof(a8));
        printf("SIZE OF A9:%d\n", sizeof(a9));
        printf("SIZE OF A10:%d\n", sizeof(a10));
        printf("SIZE OF A11:%d\n", sizeof(a11));
        printf("SIZE OF A12:%d\n", sizeof(a12));
        printf("SIZE OF A13:%d\n", sizeof(a13));
                                                  
        return 0;
}




Result:


SIZE OF A1:4
SIZE OF A2:8
SIZE OF A3:100
SIZE OF A4:8
SIZE OF A5:400
SIZE OF A6:4
SIZE OF A7:4
SIZE OF A8:4
SIZE OF A9:4
SIZE OF A10:4
SIZE OF A11:12
SIZE OF A12:8
SIZE OF A13:4




阅读(730) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~