0

If you run the following code, the console will output: LATE_

#include <iostream>
#include <string>

int main()
{
    std::cout << std::string("PLATE_" + 1);
    return 0;
}

The question is why ?

It's the same with char(1) or is there a connection here ?

  • 3
    You are invoking **pointer arithmetic**. `"PLATE_"` is a `const char[7]` array that *decays* into a `const char*` pointer to the 1st character in the array. You are then incrementing that pointer by `1` char, so the pointer advances to point at the 2nd character in the array. – Remy Lebeau Aug 09 '23 at 21:38

0 Answers0