I encountered this problem while writing a program.
#include<iostream>
using namespace std;
string a[10];
int b[10];
int main(){
string a1[10];
int b1[10];
for(auto i:a){cout<<i<<" ";}
cout<<endl;
for(auto i:b){cout<<i<<" ";}
cout<<endl;
for(auto i:a1){cout<<i<<" ";}
cout<<endl;
for(auto i:b1){cout<<i<<" ";}
cout<<endl;
return 0;
}
According to the output, elements of a and a1 are both empty strings, while b has all zero but b1 seems to have some random nubmers. I don't know what caused the difference between string and int, and between a and a1(Maybe compiler initialized variables in different scopes in different ways? So what's the purpose of this design?). Can anyone help?