How do i pass an array function without using pointers

前端 未结 7 865
广开言路
广开言路 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:27

    You can put the array into a structure like this:

    struct int_array {
        int data[128];
    };
    

    This structure can be passed by value:

    void meanval(struct int_array ar);
    

    Of course you need to now the array size at compile time and it is not very wise to pass large structures by value. But that way it is at least possible.

提交回复
热议问题