I have following code
#include <stdio.h>
#include<ctype.h>
typedef struct {
int Type;
int Type2;
}foo;
typedef struct {
char cData[40];
}bar;
int main()
{
bar b1;
strcpy(b1.cData,"11");
foo *f=(struct foo *)&b1;
printf("Type is %d \n",f->Type);
return 0;
}
But i am not getting the value of type 1 in f’s pointer , instead i am getting size of that particuler struct.
When I run the code (after correcting for errors), it prints 12593. Which is 49*256 + 49 – in other words, “11” as an integer (ascii 1 being 49). So nothing wrong with the code as far as I can see (apart from the memory layout assumptions pointed out by Benoit), so we do need to know what you expected to happen