+ 3
How to pass an array as arguments to the functions?Explain with eg code
6 Antworten
+ 10
@Ace I am pretty sure that you can...
https://code.sololearn.com/c8PGz4z7h89n/?ref=app
+ 8
By passing just name of array to function like: Function(array)
+ 3
can u explain me with example
+ 3
arrays are just contiguous blocks of memory. Now there is an array arr. arr or arr[0] or 0[arr] or * arr +(sizeof(datatype)*0) are all same. if you want to access index i that is any element of array you could use above example only, simply by replacing 0 with i and you would be able to access that in O(1) time.
So this means that once you have memory address of the first element you could access any element in constant time.
funct(int array) {// something}
func(array)
is how you would pass array to function and it would dereference it for you accordingly, similarly if you want to return array what you could do instead is return pointer to first element and dereference accordingly.
+ 2
I understood now tq@vukan
+ 1
well explained tq@shobhit