new默認初始化

using namespace std;
char arr[20];
//默認情況下,new分配的對象,不管是單個分配的還是數組中的, 都是默認初始化的。
char *p = new char[20];
cout << arr[10] << endl;
cout << int(p[10]) << endl;
cout << int(p[12]) << endl;
delete [] p;
string *pStr1 = new string[10]();
delete [] pStr1;
string *pStr = new string[10]{"hello", "a", "b"};//c++ 11 特性
cout << pStr[0] << endl;
delete [] pStr;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章