Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

Post Timeline

added 4 characters in body
Source Link
Alex K.
  • 176.8k
  • 32
  • 277
  • 299

I have two types of array inicialisationinitialisation 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╠╠╠╠╠╠R81ドル↑しかく

ad╠╠╠╠╠╠R81ドル↑しかく

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?

I have two types of array inicialisation 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╠╠╠╠╠╠R81ドル↑しかく

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?

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╠╠╠╠╠╠R81ドル↑しかく

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?

Source Link
vico
  • 18.5k
  • 54
  • 195
  • 367

Array initialization

I have two types of array inicialisation 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╠╠╠╠╠╠R81ドル↑しかく

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?

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /