Utilisation du caractère nul dans les chaînes (C ++)

Je suis brossage sur mon C++ et suis tombé sur un curieux comportement en ce qui concerne les chaînes de caractères, des tableaux de caractères, et le caractère null ('\0'). Le code suivant:

#include <iostream>
using namespace std;

int main() {
    cout << "hello
#include <iostream>
using namespace std;
int main() {
cout << "hello\0there"[6] << endl;
char word [] = "hello\0there";
cout << word[6] << endl;
string word2 = "hello\0there";
cout << word2[6] << endl;
return 0;
}
there"
[6] << endl; char word [] = "hello
#include <iostream>
using namespace std;
int main() {
cout << "hello\0there"[6] << endl;
char word [] = "hello\0there";
cout << word[6] << endl;
string word2 = "hello\0there";
cout << word2[6] << endl;
return 0;
}
there"
; cout << word[6] << endl; string word2 = "hello
#include <iostream>
using namespace std;
int main() {
cout << "hello\0there"[6] << endl;
char word [] = "hello\0there";
cout << word[6] << endl;
string word2 = "hello\0there";
cout << word2[6] << endl;
return 0;
}
there"
; cout << word2[6] << endl; return 0; }

produit de la sortie:

> t
> t
>

Ce qui se passe derrière les coulisses? Pourquoi la chaîne de caractères littérale et l'déclaré char tableau stocker les 't' à l'indice 6 (d'après l'interne '\0'), mais la chaîne déclarée ne l'est pas?

source d'informationauteur ewok