What is the type of string literal in C? Is it char *
or const char *
or const char * const
?
What about C++?
A C string literal has type char [n]
where n
equals number of characters + 1 to account for the implicit zero at the end of the string.
The array will be statically allocated; it is not const
, but modifying it is undefined behaviour.
If it had pointer type char *
or incomplete type char []
, sizeof
could not work as expected.
Making string literals const
is a C++ idiom and not part of any C standard.