I have two types of array initialisation that will be used in string constructor
int main() {
//char foo [] = { 'a', 'd' };
char foo[] = "ad";
std::string s = foo;
cout<<s;
int i;
cin >> i;
}
Why in char foo [] = { 'a', 'd' }; case i have output:
ad╠╠╠╠╠╠R8$1↑■╬
And when array is initialized like char foo [] = "ad"; I have normal output -ad- that was expected in first case.
What is difference in these two array initialization and why I have garbage in output in first one?
char foo [] = { 'a', 'd' };does not have a terminating null character, butchar foo [] = "ad";does.