I created a simple program:
#include <stdio.h>
int main()
{
int s1;
int s2;
int s3;
int *p1, *p2, *p3;
p1 = &s1;
p2 = &s2;
p3 = &s3;
printf("%d\n%d\n%d", p1, p2, p3);
}
Whenever I run this program, it prints the memory addresses of pointers p1
, p2
and p3
and the interesting thing is that these values have differences of 12
. I want to know the reason behind this. Why do the addresses differ by 12
?
Note: This happens each time I execute the program.
Output:
I tested the same program in many type of variables , the results i gets are ..
When variables are char type.
When variables are long type
When i declare int array , size each array is 1.
When size of second declared array is 2 , it gets extra 4 byte offset.