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?
相关问题
- Multiple sockets for clients to connect to
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
- Equivalent of std::pair in C
simply pass the location of base element and then accept it as 'int a[]'. Here's an example:-
You can put the array into a structure like this:
This structure can be passed by value:
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.
There is one more way: by passing size of array along with name of array.
How about varargs? See
man stdarg
. This is how printf() accepts multiple arguments.If i say directly then it is not possible...!
but you can do this is by some other indirect way
1> pack all array in one structure & pass structure by pass by value
2> pass each element of array by variable argument in function