Storage for Strings in C
In C, a string can be referred either using a character pointer or as a character array.
Strings as character arrays
char str[4] = "GfG" ; /*One extra for string terminator*/ /* OR */ char str[4] = {‘G’, ‘f’, ‘G’, '\0' }; /* '\0' is string terminator */ |
When strings are declared as character arrays, they are stored like other types of arrays in C. For example, if str[] is an auto variable then string is stored in stack segment, if it’s a global or static variable then stored in data segment, etc.
No comments:
Post a Comment