odd behavior with Character Arrays

Rohit Arul Raj rohitarulraj@gmail.com
Fri Aug 8 09:38:00 GMT 2008


On Fri, Aug 8, 2008 at 12:24 PM, Mateusz Loskot <mateusz@loskot.net> wrote:
> Rohit Arul Raj wrote:
>>
>> 2. Can i get more details as to why if the size of the array is not
>> provided the compiler does not insert an string terminator at the end
>> of the array.
>
> How could that be?
> It is an array but not a string literal, so compiler does not append \0 or
> any other extra elements to it.
>
> Best regards
> --
> Mateusz Loskot, http://mateusz.loskot.net
> Charter Member of OSGeo, http://osgeo.org
>


Hi,

If i give the size of the array as 15, like "unsigned char n[15] =
{'a', 'b', 'c','d'};" , then it is appending '\0'.
But if the size of the array is not given "unsigned char n[] ", then
it is not appending '\0'.

Does that mean, that if the size of the array is specified, it appends
'\0' and if it is not specified then it does not append '\0'?
Can you/anyone clarify this point?

Regards,
Rohit



More information about the Gcc-help mailing list