Beginner in c++ here.
why do i get the following error message when i run this code?
mismatched types 'const _Tp [_Nm]' and 'int*'
#include <bits/stdc++.h>
using namespace std;
void f(int arr[]){
int arr_size = size(arr);
for (int i = 0; i < arr_size; i++){
cout << arr[i] << " ";
}
}
int main(){
int array[5] = {1,2,3,4,5};
f(array);
return 0;
}
I tried this and it works as expected.
#include <bits/stdc++.h>
using namespace std;
int main(){
int array[5] = {1,2,3,4,5};
int arr_size = size(array);
for (int i = 0; i < arr_size; i++){
cout << array[i] << " ";
}
return 0;
}
Can someone explain what went wrong and how to fix it? Thanks.