+ 3

Array in parameters of a function?

i need help, i dont know how i can do this.

25th Sep 2018, 4:41 AM
Shoot Killer
Shoot Killer - avatar
4 Answers
+ 3
//What's the problem? //If you want array to be passed as the argument commonly the array name and length of the array is passed(There is difference between parameter and argument). //here is a sample that void func(array_name, length){ for(i = 0; i <length ; i++){ cout << "Array values: " << array_name[i]<< endl; } } //this function prints the elements in an array.
25th Sep 2018, 5:01 AM
Akib - avatar
+ 3
25th Sep 2018, 11:40 PM
Fajar Maftuh Fadli
Fajar Maftuh Fadli - avatar
+ 2
int seq[] = {1, 2, 3}; void foo(int* begin, int* end); foo(seq, seq + 3); void bar(int arr[], int size); bar(seq, 3); As an argument, an array name decays to a pointer to it's first element, so there's not much difference between foo and bar.
25th Sep 2018, 5:26 AM
Hoàng Nguyễn Văn
Hoàng Nguyễn Văn - avatar
If a size of an array is known at compilation time you can also do the following. https://code.sololearn.com/cU2T7Z6T5WKh/?ref=app
26th Sep 2018, 6:05 AM