????2. ?о?
??????c++?У????????new/delete????????????檔???????????new???÷???????????????????
int* p1 = new int;
int* p2 = new int();
int* p3 = new int(1);
// define class A;
A* p4   = new A;
A* p5   = new A();
A* p6   = new A[10];
A* p7   = new A[10]();
????????д??????????????????????????????????????г????????????????????????p3?????????????memset????????new A??new A()?????÷???????????????????????
?????????C++ Primer?? Fourth Edition????5.11??[1] The new and delete Expressions?й???new????????new A????Default Initializing of Dynamically Allocated Objects???????????????????????????new A()??????Value Initializing of Dynamically Allocated Objects????????????????????????
?????????????????????????????????????????????????????????2.3.4??[2]Variable Initialization Rules???????г??????
?????????????????????κ?????????????????????????0??????????????????????????????????????????????г????
??????????????????????????????????
?????????????????????????????????????????????????????????????????г??????????
???????new???÷?????????????????????£?
?????????????????н????????
????p1????????δ?????????int???
????p2?????????????????int???????0
????p3?????????????????int???????1
????p4???????????????????????????A??????A????????????A???????г??????????A??????δ?????????
????p5???????????????????????????A????A?????????????????A??????????????????????????????????????A?????????????????????
????p6??p7???????????????????????A?????飬????н???p4??p5
???????????????????sample?????????????????????????c++?????new sample????н????sample?е?ptr_table??????????????????windows??????μ????????linux????????????????0???????stackoverflow???????????????????[3]????????“Memory coming from the OS will be zeroed for security reasons….the C standard says nothing about this. This is strictly an OS behavior. So this zeroing may or may not be present on systems where security is not a concern”?????????????????????????????????????????????г??????????????????????????????????ж?????????????????????????????????linux??????????????????????????????????鱻?????????檔
????????????????????????????????????????????????????????????????????????????????????????????????й????????????????????????????????棬????????????
int size = 10;
{
int * p1 = new int[size];
for (int i = 0; i < size; i++)
{
p1[i] = i + 200;
printf("%d "?? p1[i]);
}
printf(" ");
delete []p1;
}
{
int * p1 = new int[size];
for (int i = 0; i < size; i++)
printf("%d "?? p1[i]);
delete []p1;
}
printf(" ");
??????н????

??????????????????????????????????????
????3. ???
????(1) ????е???????????????c++????淶?????????????????δ???????????????????????????????????????????????????????????????????????c++?????????????????
????(2) ???class/struct???????????????????????????????new???÷???????????????????????д????????????