Typing diary
c++ 메모리 동적할당 초기화, 메모리 누수 본문
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include <iostream> using namespace std; class Circle { public: Circle() {} Circle(int a) {} }; int main() { int *p = new int(10); //동적생성 초기화 cout << *p; // 10을 출력한다. //int *p = new int[10](5); -> 배열은 안된다. Circle *q = new Circle(30); //Circle(30) 생성자 호출 delete q; //※메모리 누수 int *a = new int; int b; a = &b; //a가 b를 가리키게 되어 4바이트 메모리가 누수된다. } | cs |
'C, C++' 카테고리의 다른 글
c++ 참조 (0) | 2022.08.16 |
---|---|
c++ 복사 생성자 (0) | 2022.08.16 |
string 문자열 (0) | 2022.08.16 |
명품 c++ programming 4강 Open Challenge (0) | 2022.08.16 |
명품 C++ programming 3강 2번문제 (0) | 2022.08.16 |