h-----------------------------
#include "newandmalloc.h"
#include <iostream>
using namespace std; newAndMalloc::newAndMalloc()
{
cout<<"construct newAndMalloc..."<<endl;
} newAndMalloc::~newAndMalloc()
{
cout<<"destruct newAndMalloc..."<<endl;
deletePInt();
deletePPInt();
deletePPPInt();
} void newAndMalloc::newPInt()
{
cout<<"new m_pInt..."<<endl; m_pInt = new int[m_size]; //开辟空间 for (int i = ; i < m_size; i++) //赋值
{
m_pInt[i] = m_size - i;
}
} void newAndMalloc::newPPInt()
{
cout<<"new m_ppInt..."<<endl; m_ppInt = new int*[m_size]; //开辟一维的空间
for (int i = ; i < m_size; i++)
{
m_ppInt[i] = new int[m_size]; //开辟二维的控件
} for (int i = ; i < m_size; i++) //赋值
{
for (int j = ; j < m_size; j++)
{
m_ppInt[i][j] = i + j;
}
} } void newAndMalloc::newPPPInt()
{
cout<<"new m_pppInt..."<<endl; m_pppInt = new int**[m_size]; //开辟一维的空间
for(int i = ; i < m_size; i++)
{
m_pppInt[i] = new int*[m_size]; //开辟二维的空间
for (int j = ; j < m_size; j++)
{
m_pppInt[i][j] = new int[m_size]; //开辟三维的空间
}
} for (int i = ; i < m_size; i++) //赋值
{
for (int j = ; j < m_size; j++)
{
for (int h = ; h < m_size; h++)
{
m_pppInt[i][j][h] = i + j + h;
}
}
}
} void newAndMalloc::printPInt()
{
cout<<"print m_pInt..."<<endl; for (int i = ; i < m_size; i++)
{
cout<<m_pInt[i]<<" ";
}
cout<<endl;
} void newAndMalloc::printPPInt()
{
cout<<"print m_ppInt..."<<endl; for (int i = ; i < m_size; i++)
{
for (int j = ; j < m_size; j++)
{
cout<<m_ppInt[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
} void newAndMalloc::printPPPInt()
{
cout<<"print m_pppInt..."<<endl; for (int i = ; i < m_size; i++)
{
for (int j = ; j < m_size; j++)
{
for (int h = ; h < m_size; h++)
{
cout<<m_pppInt[i][j][h]<<" ";
}
cout<<endl;
}
cout<<endl;
}
cout<<endl;
} void newAndMalloc::deletePInt()
{
cout<<"delete m_pInt..."<<endl;
delete[] m_pInt;
} void newAndMalloc::deletePPInt()
{
cout<<"delete m_ppInt..."<<endl;
for (int i = ; i < m_size; i++)
{
delete[] m_ppInt[i];
}
delete[] m_ppInt;
} void newAndMalloc::deletePPPInt()
{
cout<<"delete m_pppInt..."<<endl;
for (int i = ; i < m_size; i++)
{
for (int j = ; j < m_size; j++)
{
delete[] m_pppInt[i][j];
}
delete[] m_pppInt[i];
}
delete[] m_pppInt;
} testClass::testClass()
{
cout<<"construct testClass..."<<endl;
} testClass::~testClass()
{
cout<<"destruct testClass..."<<endl;
} cpp--------------------------------
#include "newandmalloc.h"
#include <iostream>
using namespace std; newAndMalloc::newAndMalloc()
{
cout<<"construct newAndMalloc..."<<endl;
} newAndMalloc::~newAndMalloc()
{
cout<<"destruct newAndMalloc..."<<endl;
deletePInt();
deletePPInt();
deletePPPInt();
} void newAndMalloc::newPInt()
{
cout<<"new m_pInt..."<<endl; m_pInt = new int[m_size]; //开辟空间 for (int i = ; i < m_size; i++) //赋值
{
m_pInt[i] = m_size - i;
}
} void newAndMalloc::newPPInt()
{
cout<<"new m_ppInt..."<<endl; m_ppInt = new int*[m_size]; //开辟一维的空间
for (int i = ; i < m_size; i++)
{
m_ppInt[i] = new int[m_size]; //开辟二维的控件
} for (int i = ; i < m_size; i++) //赋值
{
for (int j = ; j < m_size; j++)
{
m_ppInt[i][j] = i + j;
}
} } void newAndMalloc::newPPPInt()
{
cout<<"new m_pppInt..."<<endl; m_pppInt = new int**[m_size]; //开辟一维的空间
for(int i = ; i < m_size; i++)
{
m_pppInt[i] = new int*[m_size]; //开辟二维的空间
for (int j = ; j < m_size; j++)
{
m_pppInt[i][j] = new int[m_size]; //开辟三维的空间
}
} for (int i = ; i < m_size; i++) //赋值
{
for (int j = ; j < m_size; j++)
{
for (int h = ; h < m_size; h++)
{
m_pppInt[i][j][h] = i + j + h;
}
}
}
} void newAndMalloc::printPInt()
{
cout<<"print m_pInt..."<<endl; for (int i = ; i < m_size; i++)
{
cout<<m_pInt[i]<<" ";
}
cout<<endl;
} void newAndMalloc::printPPInt()
{
cout<<"print m_ppInt..."<<endl; for (int i = ; i < m_size; i++)
{
for (int j = ; j < m_size; j++)
{
cout<<m_ppInt[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
} void newAndMalloc::printPPPInt()
{
cout<<"print m_pppInt..."<<endl; for (int i = ; i < m_size; i++)
{
for (int j = ; j < m_size; j++)
{
for (int h = ; h < m_size; h++)
{
cout<<m_pppInt[i][j][h]<<" ";
}
cout<<endl;
}
cout<<endl;
}
cout<<endl;
} void newAndMalloc::deletePInt()
{
cout<<"delete m_pInt..."<<endl;
delete[] m_pInt;
} void newAndMalloc::deletePPInt()
{
cout<<"delete m_ppInt..."<<endl;
for (int i = ; i < m_size; i++)
{
delete[] m_ppInt[i];
}
delete[] m_ppInt;
} void newAndMalloc::deletePPPInt()
{
cout<<"delete m_pppInt..."<<endl;
for (int i = ; i < m_size; i++)
{
for (int j = ; j < m_size; j++)
{
delete[] m_pppInt[i][j];
}
delete[] m_pppInt[i];
}
delete[] m_pppInt;
} testClass::testClass()
{
cout<<"construct testClass..."<<endl;
} testClass::~testClass()
{
cout<<"destruct testClass..."<<endl;
} main-------------------------------
#include <iostream>
#include <stdio.h>
#include "newandmalloc.h" int main(int argc, char *argv[])
{
newAndMalloc *nam = nullptr;
nam = new newAndMalloc();
nam->newPInt();
nam->newPPInt();
nam->newPPPInt(); nam->printPInt();
nam->printPPInt();
nam->printPPPInt(); delete nam;
return ;
} 打印输出------------------------
construct newAndMalloc...
new m_pInt...
new m_ppInt...
new m_pppInt...
print m_pInt... print m_ppInt... print m_pppInt... destruct newAndMalloc...
delete m_pInt...
delete m_ppInt...
delete m_pppInt...

C++ new delete 一维数组 二维数组 三维数组的更多相关文章

  1. C语言malloc函数为一维,二维,三维数组分配空间

    c语言允许建立内存动态分配区域,以存放一些临时用的数据,这些数据不必在程序的声明部分定义,也不必等到函数结束时才释放,而是需要时随时开辟,不需要时随时释放,这些数据存储在堆区.可以根据需要,向系统申请 ...

  2. python如何删除二维或者三维数组/列表中某维的空元素

    如题,个人在使用python进行数据预处理过程中出现的问题,抽象成删除三维列表中某维为空的问题. 一.首先来看一下三维数组/列表的结构 仔细看下图就会很清楚了: 轴0即是去除第一个外括号后第一层(我把 ...

  3. BZOJ3132 上帝造题的七分钟 【二维树状数组】

    题目 "第一分钟,X说,要有矩阵,于是便有了一个里面写满了0的n×m矩阵. 第二分钟,L说,要能修改,于是便有了将左上角为(a,b),右下角为(c,d)的一个矩形区域内的全部数字加上一个值的 ...

  4. Java基本语法-----java数组(一维数组二维数组)

    嘿嘿!你们懂的,又是图片,委屈大家了. java数组(一维数组二维数组) [正在看本人博客的这位童鞋,我看你气度不凡,谈吐间隐隐有王者之气,日后必有一番作为!下面有个"顶"字,你就 ...

  5. Java一维与二维数组的拷贝与排序

    Java一维与二维数组的拷贝与排序 目录 Java一维与二维数组的拷贝与排序 Arrays.sort() 一维数组升序排序 二维数组按行升序排序 二维数组按列升序排序 Java中的数组 Java中数组 ...

  6. POJMatrix(二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 22058   Accepted: 8219 Descripti ...

  7. poj 1195:Mobile phones(二维树状数组,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14489   Accepted: 6735 De ...

  8. [poj2155]Matrix(二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 25004   Accepted: 9261 Descripti ...

  9. [POJ2155]Matrix(二维树状数组)

    题目:http://poj.org/problem?id=2155 中文题意: 给你一个初始全部为0的n*n矩阵,有如下操作 1.C x1 y1 x2 y2 把矩形(x1,y1,x2,y2)上的数全部 ...

  10. BZOJ 1452 Count(二维树状数组)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1452 题意:给出一个数字矩阵(矩阵中任何时候的数字均为[1,100]),两种操作:(1) ...

随机推荐

  1. 项目Gradle版本从4.4升级到4.6

    一.背景 Gralde版本与AGP(Android Gradle Plugin)版本具有一定的对应关系,原因在于AGP实质上作为Gradle的插件,依赖于Gradle作为宿主.因此,不同的AGP版本需 ...

  2. Wait… What Happens When my React Native Application Starts? — An In-depth Look Inside React Native

    Discover how React Native functions internally, and what it does for you without you knowing it. Dis ...

  3. C#操作XML文档

    Note: '=> ' 表示返回值 参考资料:请点击这里! 1:创建Xml文档 2:写Xml文档(必须保证有根元素) XmlDocument Xd (实例化一个对象) CreateXmlDecl ...

  4. Golang 模块(Module)官方手册

    官方原文: https://github.com/golang/go/wiki/Modules Go 1.11包括此处建议的对版本模块的初步支持.模块是Go 1.11中的实验性加入功能,并计划纳入反馈 ...

  5. 等待唤醒机制---Day25

    线程间通信 概念:多个线程在处理同一个资源,但是处理的动作(线程的任务)却不相同. 比如:线程A用来生成包子的,线程B用来吃包子的,包子可以理解为同一资源,线程A与线程B处理的动作,一个 是生产,一个 ...

  6. 不要在 MySQL 中使用“utf8”,请使用“utf8mb4”

    不要在 MySQL 中使用“utf8”,请使用“utf8mb4” 最近我遇到了一个bug,我试着通过Rails在以“utf8”编码的MariaDB中保存一个UTF-8字符串,然后出现了一个离奇的错误: ...

  7. Zifencei扩展

    fence 指令对外部可见的访存请求,如设备 I / O 访问,内存访问等进行串行化.外部可见是指对处理器的其他核心.线程,外部设备或协处理器可见. fence.i 指令同步指令和数据流.在执行 fe ...

  8. 企业安全之APT攻击防护

    现在针对企业APT[1]攻击越来越多了,企业安全也受到了严重的威胁,由于APT攻击比较隐匿的特性[2],攻击并不能被检测到,所以往往可以在企业内部网络潜伏很长时间. APT的攻击方式多种多样,导致企业 ...

  9. VUE--v-on修饰符

    1.v-on的修饰符 .stop:阻止事件冒泡 <div @click="getTitle"> 阿Q <button @click="getBut&qu ...

  10. flink SourceFunction SinkFunction timeWindowAll reduce

    1.实现SourceFunction接口生成数据源 /** * @Description: 产生数据 traceid,userid,timestamp,status,response time */ ...