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; }

11th Nov 2018, 7:24 PM
Igor The Golden Fish
Igor The Golden Fish - avatar
3 odpowiedzi
+ 8
You're welcome Игорь Золотая Рыбка 👍😆
11th Nov 2018, 7:38 PM
Uni
Uni - avatar
+ 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++ ;) )
11th Nov 2018, 7:34 PM
Uni
Uni - avatar
+ 1
Thanksssssssssssssssss)))) much very)
11th Nov 2018, 7:37 PM
Igor The Golden Fish
Igor The Golden Fish - avatar