There's no meaningful explanation of the behavior of your code at the level of C language. You code sample contains erroneous code as well as code producing undefined behavior. So, the results you observe can only be explained by half-random half-implementation-dependent manifestations of that undefined behavior.
In particular, the following issues exist in your code.
p = &a;
This is illegal. &a
has type int (*)[5]
, while p
is declared as int *
. Assignment from such incompatible type is not allowed in C. It is a constraint violation in C, i.e. it is what is normally supposed to result in compilation error.
void main()
Function main
in C is required to return int
, not void
.
printf("%u\n",p);
printf(" %u \n",&a);
printf("%u",q);
Trying to print pointer values by using %u
format specifier causes undefined behavior. %u
requires an unsigned int
argument, not a pointer argument.
Now, the typical behavior of such broken code (if you manage to force it through some lenient compiler) would usually produce the follwing. The value of q
you observe is the location of pointer p
in memory. The value of &a
you observe is the location of array a
in memory. So, the difference of 8 bytes that you observe simply means that p
and a
are located 8 bytes from each other in memory. p
resides at lower address, while a
resides at higher address. That's all there is to it.