+ 3

How to pass an array as arguments to the functions?Explain with eg code

25th Jan 2018, 3:22 PM
PRAVALLIKA.K
PRAVALLIKA.K - avatar
8 odpowiedzi
+ 10
@Ace I am pretty sure that you can... https://code.sololearn.com/c8PGz4z7h89n/?ref=app
25th Jan 2018, 3:42 PM
Vukan
Vukan - avatar
+ 8
By passing just name of array to function like: Function(array)
25th Jan 2018, 3:26 PM
Vukan
Vukan - avatar
+ 3
can u explain me with example
25th Jan 2018, 3:42 PM
PRAVALLIKA.K
PRAVALLIKA.K - avatar
+ 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.
25th Jan 2018, 5:26 PM
shobhit
shobhit - avatar
+ 2
I understood now tq@vukan
25th Jan 2018, 3:46 PM
PRAVALLIKA.K
PRAVALLIKA.K - avatar
+ 1
well explained tq@shobhit
27th Jan 2018, 11:24 AM
PRAVALLIKA.K
PRAVALLIKA.K - avatar