How do i pass an array function without using pointers

前端 未结 7 1027
广开言路
广开言路 2021-02-05 21:04

I have been asked in an interview how do you pass an array to a function without using any pointers but it seems to be impossible or there is way to do this?

7条回答
  •  猫巷女王i
    2021-02-05 21:48

    Put the array into a structure:

    #include 
    typedef struct
    {
      int Array[10];
    } ArrayStruct;
    
    void printArray(ArrayStruct a)
    {
      int i;
      for (i = 0; i < 10; i++)
        printf("%d\n", a.Array[i]);
    }
    
    int main(void)
    {
      ArrayStruct a;
      int i;
      for (i = 0; i < 10; i++)
        a.Array[i] = i * i;
      printArray(a);
      return 0;
    }
    

提交回复
热议问题