Consider the following programme
void main()
{
char str[]="\12345s\n";
printf("%d",sizeof(str));
}
Output is :6
can someone explain me why.And is sizeof contain null value while
gigving the size of any string.
Consider the following programme
void main()
{
char str[]="\12345s\n";
printf("%d",sizeof(str));
}
Output is :6
can someone explain me why.And is sizeof contain null value while
gigving the size of any string.
char str[] = "\12345s\n";
This is equivalent to the following.
char str[] = {0123,'4','5','s','\n','\0'};
The array has six elements, each of one byte in size -- so sizeof reports the array size as 6.
And if you said:
void main()
{
char *str ="\12345s\n";
printf("%d",sizeof(str));
}
The output will be 4, the size of a pointer (not the size of what it points to)
char str[]="[b]\[/b]12345s\n";
how it is treated like this first element like 0123.it is very much confusing pls clear my doubt.
You used an escape sequence.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.