内存的本质是资源,由操作系统分配。 在代码中申请和归还内存。
在c++中申请内存new 释放内存delete.
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
int *p = new int;
*p = 20;
if (p!=NULL)
{
cout << *p << endl;
}
delete p;
p = NULL;
int *q = new int[10];
delete[] q;
q = NULL;
return 0;
}