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;
}
because
printf("[%s]\n" , s->b);prints the data from the address s->b to the character'\0'. after the addresss->bwhenever it will find the'\0'it will print the data.above statement do not include
'\0'at the last character so it will continue reading the data from the address untill it find String terminator'\0'