int main()
{
int n = 3;
int a[n] = {1,2,3};
...
in middle of code, value of n can be increased by 10 so I want to have check before cout otherwise a[10] is out of bound.
...
cout<<a[n-1];
return 0;
}
To fix above issue, I simply put one if check.
Corrected code:
int main()
{
int n = 3;
int a[n] = {1,2,3};
...
In middle of code, value of n can be increased by 10 so I want to have check before cout otherwise a[10] is out of bound.
...
if(n<= 3)
{
cout<<a[n-1];
}
return 0;
}
Is there any other way to avoid Out of Bound Memory Access
I tried to use if check on the basis of size.