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. hibernate中many-to-one的not-found属性和@notfound注解

    如果在Hibernate项目里面配了很多many-to-one的关联,即使后台在查询数据时已经作了健全性判断,但还是会经常抛出对象找不到异常:org.hibernate.ObjectNotFoundE ...

  2. 使用excel中的数据快速生成sql语句

    在小公司的话,总是会有要开发去导入历史数据(数据从旧系统迁移到新系统上)的时候.这个时候,现场实施或客户会给你一份EXCEL文档,里面包含了一些别的系统上的历史数据,然后就让你导入到现在的系统上面去. ...

  3. tk.mybatis 中一直报...table doesn't exists

    首先检查你在实体类中可有加上@Table(name="数据库中的表名") 第二:如果你加了@Table注解, 那么只有一种可能就是.xml中定义了与通用mapper中的相同的方法名 ...

  4. 目标检测算法之Fast R-CNN和Faster R-CNN原理

    一.Fast R-CNN原理 在SPPNet中,实际上特征提取和区域分类两个步骤还是分离的.只是使用ROI池化层提取了每个区域的特征,在对这些区域分类时,还是使用传统的SVM作为分类器.Fast R- ...

  5. C#反射_两合并更新实体

    #region 更新实体模型 /// <summary> /// 更新实体模型 /// </summary> /// <typeparam name="T&qu ...

  6. Python【day 9】函数入门2

    本节内容:1. 什么是函数2. 函数定义, 函数名, 函数体以及函数的调⽤3. 函数的返回值4. 函数的参数 一.什么是函数 我们可以先去定义一个事情或者功能(接口.服务.函数.功能). 等到需要的时 ...

  7. GIT篇章(一)

    git的使用 创建代码版本 cd进入到自己希望存储代码的目录路径,并创建本地仓库.git[pycharm直接打开终端就是项目根目录了.无须cd了] 新创建的本地仓库.git是个空仓库 cd 目录路径 ...

  8. html书写行内元素时-tab和换行会在行内元素间引入间距

    目录 html文本中的控制字符会被解析为文本节点 书写行内元素时,换行符LF与水平制表符HT会引入莫名的元素间间隔 其他控制字符是否会引入间距的验证 html文本中的控制字符会被解析为文本节点 举例: ...

  9. 01. JavaScript基础总结深入

    01. 数据类型 1. 分类(2大类) * 基本(值)类型 * Number: 任意数值 * String: 任意文本 * Boolean: true/false * undefined: undef ...

  10. 实验吧——who are you?(insert into注入 二分法 时间盲注)

    题目地址:http://ctf5.shiyanbar.com/web/wonderkun/index.php 根据提示  “我要把攻击我的人都记录db中去!”  猜测这是insert into注入,会 ...