I don't understand why this program print "klmnop" and not just "klm". b is an array of size 2! This is the code:
struct S
{
int i1;
int i2;
char b[2];
};
int main()
{
char a[] = "abcdefghijklmnop";
struct S* s = a + 2;
printf("[%s]\n" , s->b);
return 0;
}
sizeof(int)is 8 bytes? What are you trying to achieve?char *tostruct S *with no real guarantee of alignment. But I think the point was clear enough. It could have just beenprintf("[%s]\n", a+10)though. It looks like a reduced form of a larger, non-hypothetical problem.