I'm passing an array in function argument and when I tried to access the last element using arr[-1]
in the function's body I'm getting some garbage. Can someone explain me why is that so?
Here is the code:
#include<stdio.h>
using namespace std;
int binsearch(int nelement, int arr[],int maxsize)
{
int low = 0;
int high = maxsize;
printf("%d",arr[-1]);
return 0;
}
void main()
{
int arr[] = {1,2,3,4,5,6,7,8,9};
int flag = 3;
printf("%d\n",arr[8]);
flag = binsearch(flag,arr,sizeof(arr));
}
And here is the output:
9
-858993460