结果cout&lt;&lt; “你好”+ 1&lt; <endl; (c ++)=“”

时间:2017-06-01 04:13:38

标签: c++ cout

=“”

您能否帮我解释一下以下代码的结果。

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

为什么结果出现为“ello”,我知道打印出Hello1然后我应该使用: COUT&LT;&LT; “你好”&lt;&lt; 1·;&LT; ENDL; 但任何人都可以帮我解释上面代码的顺序: 非常感谢。

1 个答案:

答案 0 :(得分:4)

你的例子大致相当于:

// `p` points to the first character 'H' in an array of 6 characters
// {'H', 'e', 'l', 'l', 'o', '\0'} 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;
相关问题