#Why are character arrays ended with a '/0' while other ones do not have terminating characters?

9 messages · Page 1 of 1 (latest)

pearl wyvern
#

I mean is it just a convenience thing, so we don't have to get the length of our strong when we want to use it?

torpid needleBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

errant topaz
#

The \0 character does not mark the "end of the array". The \0 character marks the end of the string stored in a char array, if (and only if) that char array is intended to store a string.

pearl wyvern
#

That broadens my view of things thanks

#

!solved

torpid needleBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

errant topaz
#

From stack overflow there is a part that says there are multiple ways to declare character array.

Ex:

char str1[]    = "my string";
char str2[64]  = "my string";
char str3[]    = {'m', 'y', ' ', 's', 't', 'r', 'i', 'n', 'g', '\0'};
char str4[64]  = {'m', 'y', ' ', 's', 't', 'r', 'i', 'n', 'g' };
quartz thistle
#

Not all character arrays have \0 at the end. If you do char arr[] = {'a', 'b', 'c'};, it won't have one

#

But "abc" would. So there's no inconsistency between char and other types here