Community
Participate
Working Groups
Hi I wrote a short program of the dynamic array,the result is not the expect.but I got it when i execute it directly in windows,the following is the part of the program: int main() { string *psa = new string[10]();//this array initialized int *pia = new int[10]; //this array not initialized bitset<32> bs(*pia); cout << "psa first element: " << *psa << endl; //ok,the result is blank cout << "pia first element: " << *pia << endl; //should be random digit in int scope cout << "pia bitset: " << bs << endl; //should be all zeros const int *pci_ok = new const int[100](); //this array initialized cout << "const dynamic array: " << *pci_ok << endl; //should be 0 } CDT console output is : psa first element: pia first element: 3998328 pia bitset: 00000000001111010000001001111000 const dynamic array: 4017984 but the direct executing result is : psa first element: pia first element: 0 pia bitset: 00000000000000000000000000000000 const dynamic array: 0
I doubt cdt console changing output on you, which means this is depends on launch environment, which probably means stuff you think is initialized isn't.
From my C++ knowledge there is no difference between x a[]; and x a[](); Default constructor will be called in any case. In case of "int" - there is no constructor.
(In reply to comment #2) > From my C++ knowledge there is no difference between x a[]; and x a[](); > Default constructor will be called in any case. In case of "int" > - there is no constructor. I thought it was,they are primitive,and have no constructor.but i got that the x a[](); will be initialized with default "ZERO",x a[]; will not from <<C++ primer>>. This is not the point, I just want to know about the reason of the difference between the CDT console(may be should be call eclipse console) output and the program direct output. I want to know how can I solved this problem, if caused by launch environment. Thanks
In C/C++ world, nothing is initialized by default. If you don't write code to initialize your structures, they contain random bits. This has nothing to do with CDT or Eclipse.
You should not spent any time at difference between the environment, you should initialize you variables - this is only reliable solution