C question.... sizeof
char str[]="chaitanya\0kulkarni\0";
printf("%u", sizeof str);
the output shouled be 19
but it gives 20 coz it explicitely appends extra \0
why???????
char str[]="chaitanya\0kulkarni\0";
printf("%u", sizeof str);
the output shouled be 19
but it gives 20 coz it explicitely appends extra \0
why???????
char str[]="chaitnya
char str[]="chaitnya kulkarni"
no of characters here= 18 (17 words + 1 space)
now c adds one /0 ie NULL to indicate that the string has ended
so if u want to store "blub" , you need not 4 places in array but 5
this is very practical for cases like (one exmaple)
you want to go through the string and determine end of it
for(int i =0, str[i]!='/0',i++)
{
do this ...code
}