如果用sizeof()去取,各占几个字节呢?
谢谢

解决方案 »

  1.   

    同意楼上的,因为用sizeof()去取的结果都是指向char类型的指针的长度。
      

  2.   

    MSDNint  array[] = { 1, 2, 3, 4, 5 };     // sizeof( array ) is 20 
                                          // sizeof( array[0] ) is 4 
    size_t  sizearr =                        // Count of items in array
       sizeof( array ) / sizeof( array[0] );数组==>指针?不明白
      

  3.   

    char * test;
    sizeof(test) == 4;
    char test[0];
    sizeof(test) == 1;
      

  4.   

    看林悦的高质量的C++编程
    数组名在作为参数传递的时候退化为一个纯粹的指针了
    此时sizeof的时候是4,否则sizeof就是整个数组的长度的
      

  5.   

    两个是不一样的,一个是指针,一个是数组(这个大家都知道).
    但元素个数等于零的数组在编译(levels 2 and 4)时会有警告.vc6下sizeof()的值两个显然不同第一个时一个指针的大小4,而第二个是整个数组的大小0
      

  6.   

    晕了,实践出真知, netxy的是在vc6下运行的结果么?
      

  7.   

    大家是不是认为sizeof()也是函数调用.
    char test[0];
    sizeof(test)中的test也会退化成指针.如果退化的话,你用什么得到数组的大小,愿请教.
      

  8.   

    那一个数组是如何申请空间的呢?如何摆放?汇编码什么样呢?
    就以test[0]为例
      

  9.   

    to skiptomylou(溪西)
    你先说说你的见解.
      

  10.   

    看书之后觉得test[0],字符串数组中都要在末尾放'\0',所以sizeof()是2
      

  11.   

    建议char *test; int test[0];
    再sizeof()试一下看看;
      

  12.   

    char test[0] cannot pass through the compilation. If change to char test[1] then the result will 4, 1 respectively.
      

  13.   

    zhouzhaohan() ( ) 信誉:100 C中,在struct中定义的char *test和char test[0]有什么区别呢?
    char *test定义了一根指针,占用空间。
    char test[0]只定义了一个符号test,并不实际占用空间,是对c语言的一个扩展。
    至于sizeof是多大,哪要看你的结构如何定义,结构中的成员顺序如何。
    GCC中有这个扩展,richard stallman 是这样解释这种做法的原因和使用方法的:
    Arrays of Length ZeroZero-length arrays are allowed in GNU C. They are very useful as the last element of a structure which is really a header for a variable-length object: struct line {
      int length;
      char contents[0];
    };{
      struct line *thisline = (struct line *)
        malloc (sizeof (struct line) + this_length);
      thisline->length = this_length;
    }In standard C, you would have to give contents a length of 1, which means either you waste space or complicate the argument to malloc.