A C string is a bunch of characters terminated by a '\0' byte. Your char array is
one byte too short to store that trailing '\0' byte so the printf function prints that
following short as if it were two bytes; luckily enough one of the bytes in that
short contains a '\0' value. Change your assignment to b.len= 0x4141 and see
the disaster.
kind regards,
Jos
Hi Jos
Thanks for the quick response...
array starts with "0" in this case i have given char str1[20] and string consists of 20 characters "12345678901234567891" It starts with 0 and ends with 19 and there is a space to store '\0' value in the place of str1[20]. only when i assign the value for b.len = 1 then there is a change in str1 value.....
secondly if the struct consist like this
struct a
{
short len;
char str1[20];
};
in this case first variable is short declared then comes char....the order is changed in the above structure. now iam not getting the issue. its working fine.
why is the difference? is there any order is maintained internally.
Please advice me...
awaiting for ur reply