Here is what I was trying to do:-
struct Test
{
int i;
char s;
float f;
};
int main()
{
int sizestruct=sizeof(struct Test);
printf("size of struct=%d\n", sizestruct);
int maxedge;
printf("enter maxedge value");
scanf("%d", &maxedge);
struct Test *sptr1, *sptr2;
sptr1=(struct Test *) 1000;
sptr2=(struct Test *) maxedge;
printf("sptr1=%d, sptr2=%d\n",sptr1, sptr2);
printf("then sptr2-sptr1=%d\n", sptr2-sptr1);
return 0;
}
Now, the output I am getting is ok if maxedge=1996 (output is 83). Even for values 1997, 1998 and 1999, its giving the same value. But for values from 2000 to 2007, junk value comes. From values 2008 to 2011, output is 84. But from 2012 to 2019 again, output is junk.
Now consider this struct:
struct Test {
int i;
char s;
float f;
char s1;
};
For the above struct, no matter what the value is for maxedge, the output is proper. I am unable to understand why junk value is coming for the above code!!