山东师范大学 研究生 C++高级程序设计 第2章 C++程序设计基础.pptVIP

  • 1
  • 0
  • 约4.29万字
  • 约 140页
  • 2026-02-03 发布于河北
  • 举报

山东师范大学 研究生 C++高级程序设计 第2章 C++程序设计基础.ppt

voidmain(){int*p=NULL,*t;inti;p=newint[10];if(p==NULL){coutallocationfaiure\n;return;}for(i=0;i10;i++)p[i]=100+i; coutendl;for(t=p;tp+10;t++)cout*t;coutendl;delete[]p;}例2用new运算符建立动态数组p100101102103104105106107108109t10i以下标方式访问动态数组1.new和delete操作符voidmain(){int*p=NULL,*t;inti;p=newint[10];if(p==NULL){coutallocationfaiure\n;return;}for(i=0;i10;i++)p[i]=100+i; coutendl;for(t=p;tp+10;t++)cout*t;coutendl;delete[]p;}例2用new运算符建立动态数组p100101102103104105106107108109t10ii是偏移量p指针本身值不变1.new和delete操作符voidmain(){int*p=NULL,*t;inti;p=newint[10];if(p==NULL){coutallocationfaiure\n;return;}for(i=0;i10;i++)p[i]=100+i; coutendl;for(t=p;tp+10;t++)cout*t;coutendl;delete[]p;}例2用new运算符建立动态数组p100101102103104105106107108109t10i跟踪指针赋初值1.new和delete操作符voidmain(){int*p=NULL,*t;inti;p=newint[10];if(p==NULL){coutallocationfaiure\n;return;}for(i=0;i10;i++)p[i]=100+i; coutendl;for(t=p;tp+10;t++)cout*t;coutendl;delete[]p;}例2用new运算符建立动态数组p100101102103104105106107108109t10i跟踪指针移动1.new和delete操作符voidmain(){int*p=NULL,*t;inti;p=newint[10];if(p==NULL){coutallocationfaiure\n;return;}for(i=0;i10;i++)p[i]=100+i; coutendl;for(t=p;tp+10;t++)cout*t;coutendl;delete[]p;}例2用new运算符建立动态数组p100101102103104105106107108109t10i间址访

文档评论(0)

1亿VIP精品文档

相关文档