1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【C++】メモリの動的確保

Posted at

メモリの動的確保で迷うことが多いので大体のパターンを書いてみます。

int* p1 = new int;  //1個のメモリを確保
int* p2 = new int(10); //1個のメモリを確保して10で初期化
int* p3 = new int[10]; //10個のメモリを確保

string* p4 = new string; //1個のメモリを確保
string* p5 = new string("hogehoge"); //1個のメモリを確保してhogehogeで初期化
string* p6 = new string[10]; //10このメモリを確保

自分で作ったクラスでも同様に動的確保ができまs

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?