结果 cout << "Hello" + 1<<endl; (C++)

Result cout << "Hello" + 1<<endl; (C++)

你能帮我解释一下下面代码的结果吗?

cout<< "Hello" + 1<< endl;

为什么结果是 "ello",我知道要打印出 Hello1 然后我应该使用: cout<< "hello" << 1<< endl; 但是谁能帮我解释一下上面代码的顺序: 太感谢了。

你的例子大致相当于:

// `p` points to the first character 'H' in an array of 6 characters
// {'H', 'e', 'l', 'l', 'o', '[=10=]'} forming the string literal.
const char* p = "Hello";
// `q` holds the result of advancing `p` by one element.
// That is, it points to character 'e' in the same array.
const char* q = p + 1;
// The sequence of characters, starting with that pointed by `q`
// and ending with NUL character, is sent to the standard output.
// That would be "ello"
std::cout << q << std::endl;