I always considered string literals as constant objects. Why are they
considered non-const if they can not be modified? Is it because they're
stored in a different area of memory than const objects?
String-literal-created arrays are in principle read-only, yes.
(Whether they are in fact read-only on any given implementation is
up to the implementation. Making them physically read-only usually
requires some kind of hardware level protection, whether it be in
the form of ROM, or page-protection, or similar; so systems without
such protection, or on which protections have been disabled for
some reason, the arrays will generally be write-able anyway.)
Now, given that "const" in C means, more or less, "read-only", I
suspect you mean to ask:
The array created by the string literal "hello" has type
"array 6 of char" instead of "array 6 of const char". Why?
The answer is, essentially, "history". Early C (before the original
1989 ANSI standard) had no "const" keyword, and hence no const-
qualified types. This meant that string-literal-created arrays
were *always* used with non-qualified pointers:
char *p = "hello";
The X3J11 (ANSI C) committee folks did not want to break existing
code, but did want to require "const" in cases like this:
const char s[6] = { 'h', 'e', 'l', 'l', 'o', '\0' };
const char *p = s;
The only way to reconcile these two desires was to make string
literals produce arrays of type "array N of char" instead of "array
N of const char".
(I always thought -- and in fact still do think -- that they should
instead have given up on the second desire, and not made "const" a
type qualifier at all, but rather merely a storage-class modifier.
This would avoid the "const char *const *argv" problem:
char **argv;
...
const char *const *p = argv; /* must draw diagnostic in C */
This particular problem is fixed in a different way in C++, and C
could adopt the C++ rules; but note that C++ already makes the
arrays produced by string literals have type "const char [N]", too.
C and C++ are sufficiently different languages that it is often
not a good idea to move concepts between them casually.)