C++(cpp)
[cpp] new, delete
Jueun Park
2021. 6. 21. 18:53
#include <iostream> // standard input, output
int main()
{
int a = 1;
int *p = new int;
*p = 10;
{
int b = 2;
std::cout << a << std::endl;
std::cout << b << std::endl;
std::cout << *p << std::endl;
}
std::cout << a << std::endl;
//std::cout << b << std::endl; --> error
std::cout << *p << std::endl;
delete p;
}
각 c의 malloc과 free에 해당함.