P
peter.xiau
I found that
std::vector<int> v(10) ;
will automatically initiallize every elem to 0 in the vector,
I check the source code (VS.NET2003),
and I found a line of code like this
*T = new T[n]() ;
So I tested the three lines of code
1. int *p = new int[10] ;
2. int *p = new int[10]() ;
3. std::vector<int> v[10] ;
In Code::Blocks(using gcc), the result is:
1. Elements do NOT be initiallized.
2. Elements do NOT be initaillized.
3. Elements are initiallized.
In VS.NET 2003, the result is:
1. Elements do NOT be initiallized.
2. Elements are initiallized.
3. Elements are initiallized.
The result confusing me,
In the C++ standard,
Does "new int[10]()" need to initiallize the elements?
Or the behavior is depend on compilers?
std::vector<int> v(10) ;
will automatically initiallize every elem to 0 in the vector,
I check the source code (VS.NET2003),
and I found a line of code like this
*T = new T[n]() ;
So I tested the three lines of code
1. int *p = new int[10] ;
2. int *p = new int[10]() ;
3. std::vector<int> v[10] ;
In Code::Blocks(using gcc), the result is:
1. Elements do NOT be initiallized.
2. Elements do NOT be initaillized.
3. Elements are initiallized.
In VS.NET 2003, the result is:
1. Elements do NOT be initiallized.
2. Elements are initiallized.
3. Elements are initiallized.
The result confusing me,
In the C++ standard,
Does "new int[10]()" need to initiallize the elements?
Or the behavior is depend on compilers?