How do i pass an array function without using pointers

前端 未结 7 864
广开言路
广开言路 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条回答
  •  走了就别回头了
    2021-02-05 21:33

    There is one more way: by passing size of array along with name of array.

    int third(int[], int ); 
    
    main() {
       int size, i;
       scanf("%d", &size);
       int a[size];
       printf("\nArray elemts");
       for(i = 0; i < size; i++)
           scanf("%d",&a[i]);
       third(a,size);
    }
    int third(int array[], int size) {
        /* Array elements can be accessed inside without using pointers */
    } 
    

提交回复
热议问题