0
Why it don't worked?
#include <iostream> using namespace std; void printArray(int arr[], int size) { for(int x=0; x<size; x++) { cout <<arr[x]; } } int main() { printArray([1, 2, 3, 4, 5], 5); return 0; }
3 Antworten
+ 8
You're welcome Игорь Золотая Рыбка 👍😆
+ 7
Try this:
#include <iostream>
using namespace std;
void printArray(int* arr, int size) {
for(int x=0; x<size; x++) {
cout <<arr[x];
}
}
int main(){
int a[]={1, 2, 3, 4, 5};
printArray(a, 5);
return 0;
}
The array variable in the function has to be treated as a pointer in the definition and after you cannot use [] with elements inside (this works in Ruby or Python but not C++ ;) )
+ 1
Thanksssssssssssssssss)))) much very)