karthikbalaguru wrote:
> Hi,
> String constant being modifiable in C++ but, not modifiable in C.
> that is,
> In C++, the following example output will be "Mplusplus"
> char *str1 = "Cplusplus";
> *str1 = 'M';
> In C, the above example will produce an error as we are trying to
> modify a constant.
>
> So, str1 is not a string constant in C++.
> Does it mean that string constant concept is absent in C++ ?
This is one of those really bad decisions by the C++ committee.
String literals are of type const char [], however, for reasons of
wisdom beyond my grasp, the standard allows sting literals (and only
string literals) to be assigned to a "char * ptr" by implicitly const
casting. More than likely, trying to modify the string literal will
cause your program to segv. Go figure.