Applying increment operators on CrazyString

Question | Mar 17, 2017 | rparekh 

The CrazyString as shown below is a custom fixed length string that overloads increment and decrement operators. The increment operators convert first and last char in CrazyString to uppercase, and decrement operators convert first and last char to lowercase. Look at the code and comments below:

template<size_t S>
struct CrazyString {

 CrazyString(const char* str=nullptr) {
    if(str) strncpy(str_, str, sizeof(str_)-1);
 }

 CrazyString& operator ++() {
    // Convert first char to uppercase
    str_[0] = toupper(str_[0]);
    return *this;
 }

 CrazyString& operator ++(int) {
    // Convert last char to uppercase
    size_t l = strlen(str_);
    if(l) str_[l-1] = toupper(str_[l-1]);
    return *this;
 }

 CrazyString& operator --() {
    // Convert first char to lowercase
    str_[0] = tolower(str_[0]);
    return *this;
 }

 CrazyString& operator --(int) {
    // Convert last char to lowercase
    size_t l = strlen(str_);
    if(l) str_[l-1] = tolower(str_[l-1]);
    return *this;
 }

 const char* c_str() const { return str_; }

private:
 char str_[S+1] = {}; // 0-Initialize
};

Note that above code is only for educational purpose, I don't foresee any practical use of CrazyString in real life. The tolower and toupper are C++ standard library functions that convert a letter to lowercase and uppercase respectively. These functions return the char unchanged if no conversion is possible.

Let's create a CrazyString instance and call the increment and decrement operators by chaining them:

CrazyString<24> cs = "hello world";

(--((++cs)--))++;

Select the correct value of cs after above operations?

std::cout << cs.c_str();