Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
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 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

Typing diary

c++ 메모리 동적할당 초기화, 메모리 누수 본문

C, C++

c++ 메모리 동적할당 초기화, 메모리 누수

Jcon 2022. 8. 16. 15:17
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 *= new int(10); //동적생성 초기화
    cout << *p; // 10을 출력한다.
    //int *p = new int[10](5); -> 배열은 안된다. 
 
    Circle *= new Circle(30); //Circle(30) 생성자 호출
    delete q;
 
    //※메모리 누수 
    int *= 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