动态分配内存: 测试代码: #include
#include
using namespace std; class myclass{ int num; char name[80]; public: myclass(int x,char *s) { num=x; strcpy(name,s); } ~myclass() { cout<<"Del class /n"; } void show() { cout<<"num is "<
<<"; name is "<
<
show(); *p=1; cl->set(*p); cl->show(); delete p; delete cl; return 0; } 测试结果: num is 0; name is yanghangjun num is 1; name is yanghangjun Del class Press any key to continue 测试代码: #include
#include
using namespace std; int main() { int *p; int i; p=new(nothrow) int[10]; //nothrow替代形式 if(!p) { cout<<"alloc memory failure/n"; return 1; } for(i=0;i<10;i++) *(p+i)=i; for(i=0;i<10;i++) cout<
<<"number is "<<*(p+i)<
动态分配内存
最新推荐文章于 2022-07-24 16:05:47 发布