我定义了
static int buf[8] ;
然后我又定义了一个函数
GetLength( int * )
我把buf当参数传到函数,在函数体中如何能求出数组的长度是8?

解决方案 »

  1.   

    can not get length of the array  by a pointer.
      

  2.   

    我还没有测试哦,呵呵
    GetLength( int *n )
    {
    for(int i = 1;;i++)
    {
      if(n[i] =='\0')
          return i;
      else
        i ++;
    }}
      

  3.   

    c没有地址越界检查,又不像java。上面那段程序的运行结果是不定的。
      

  4.   

    GetLength( int *n )
    如果但从n是无法知道长度的,因为它只是一个指针,并不带任何长度信息,你必须自己将长度传进去。
      

  5.   

    建议你还是定义一个结构题:struct _buf
    {
    int buf[8];
    int bufLength;
    };然后把结构体的指针传给函数不就结了。
      

  6.   

    microggmy() 的方法应该可以