Home

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.

previous
next

Re: Superclass and Subclasses
Re: Naming dictionaries recursively
Re: Porable Semaphore implemented in C++ ?
Re: user defined conversion operator or operator overloading?
Re: const char units[] = "ľA";
Podaruj Zycie
Rodzic Po Ludzku
Mimo Wszystko
Akogo
Nasze Dzieci