+ 3
Array in parameters of a function?
i need help, i dont know how i can do this.
4 Respuestas
+ 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.
+ 3
Did you mean like this code?
https://code.sololearn.com/cUp9dSnT5Z9U/?ref=app
+ 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.
0
If a size of an array is known at compilation time you can also do the following.
https://code.sololearn.com/cU2T7Z6T5WKh/?ref=app