In the following program, I get the output 1 0 0 2130567168 11 2686668 7 2686916
whereas according to me the output must be 1 2 3 4 5 6 7 8
because the array elements are stored in contiguous memory locations and I am accessing those elements in a contiguous fashion.
#include<stdio.h>
#include<stdlib.h>
int *fun3();
int main(){
int j, k;
int *q = fun3();
for(j = 0; j < 8; j++){
printf("%d\t", *(q+j));
}
}
int *fun3(){
int a[] = {1,2,3,4,5,6,7,8};
return a;
}
Please suggest any problems in my code or my reasoning.Why am I getting this unusual behaviour?