I was trying to access a variable through array which is out of bound index like this
#include <stdio.h>
int main(void){
int x = 8;
int arr[10];
int *ptr = &x;
printf("the address of x is : %d\n" ,ptr);
printf("the address of arr[10] is : %d\n", &arr[10]);
printf("arr[10] = %d\n",arr[10]);
printf("x = %d\n",x);
return 0;
}
The output is
the address of x is : 6422296
the address of arr[10] is :6422296
arr[10] = 8
x = 8
Can I use this technique to access any useful data or any application for this? Or is it just a useless code that spits out garbage values?