标签:
单个分配:
#include <iostream> using namespace std; int main() { int *p = new int(5); if(NULL == p) { return 0; } cout<<*p<<endl; *p = 20; cout<<*p<<endl; delete p; p = NULL; return 0; }
如图:
块分配:
#include <iostream> using namespace std; int main() { int *p = new int[1000]; if(NULL == p) { return 0; } cout<<*p<<endl; p[0] = 20; p[1] = 10; cout<<p[0]<<" , "<<p[1]<<endl; delete []p; p = NULL; return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/u012965373/article/details/46830385