Why is this code not working and what should be the correct code?
#include <iostream>
using namespace std;
int get(int arr, int i)
{
if(i >= 0 && i < sizeof(arr))
return arr[i];
return -1;
}
int main()
{
int arr[3] = {10,20,30};
cout << get(2) << endl;
return 0;
}
Can someone explain?