#include <stdio.h>
void main()
{
int p[]={0,1,2,3,4};
int *a[]={p,p+1,p+2,p+3,p+4};
printf("%u %u %u",a,*a,*(*a));
}
What *(*a) will print(will it print 0 or it’s address)?
And if we make array p as static(static int p[]), output gets changed .Why?
First of all, I think you mean 3 %u’s and not 4.
Second, you shouldn’t concern yourself with the output of the first 2: a and *a because they are the addresses assigned by the OS.
Now to answer your question, in the first case, when you’re not using static, the code space for data is allocated on the stack, and the OS uses randomization techniques, for security purposes to change the address of the variables. Which is why, the output of a and *a keeps changing.
However, once you declare p as static, it gets allocated in the data region, which is NOT randomized by the OS, and hence you get *a output as constant. BUT, a still is non-static, and hence its output will change everytime you run the program, because it is still allocated on the stack.
I hope this answers your question.
If you mean that in the first case a and *a are very close and in the second case they are not, my answer answers that too.