19.new和delete用于数组
2024-10-21 09:28:19
程序1:
//2022年9月20日22:06:27
#include <iostream>
#pragma warning(disable:4996)
using namespace std;
//1.new创建基础类型的数组
void test01()
{
//申请基础数据类型的数组
int * pInt = new int [10] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};//不推荐
for (int i = 0; i < 10; i++)
{
pInt[i] = i + 1;
}
for (int i = 0; i < 10; i++)
{
cout << pInt[i] << " ";
}
cout << endl;
char * pChar = new char[64];
memset(pChar, 0, 64);
strcpy(pChar, "小花");
cout << pChar << endl;
//注意:如果new时有中括号,那么delete时也要有中括号
delete [] pInt;
delete [] pChar;
}
int main()
{
test01();
system("pause");
return EXIT_SUCCESS;
}
输出结果:
1 2 3 4 5 6 7 8 9 10
小花
请按任意键继续. . .
最新文章
- asp.net中如何防止用户重复点击提交按钮
- STP的作用和操作
- [10]APUE:信号
- Oracle开发常用函数与存储过程
- C语言 百炼成钢16
- C#中virtual和abstract的区别
- POJ 3468 A Simple Problem with Integers (伸展树区间更新求和操作 , 模板)
- tomcat7 1000并发量配置 tomcat7配置优化
- 最简单的视音频播放示例6:OpenGL播放YUV420P(通过Texture,使用Shader)
- HDU 4009 Transfer water 最小树形图
- Docker&Kubernetes沙龙干货集锦:容器集群管理利器kubernetes详谈-CSDN.NET
- Oracle学习第二天
- 设置int、float型数据的输出格式
- (详细)php实现留言板---会话控制-----------2017-05-08
- 常见C++面试题及基本知识点总结(一)
- Docker入门书籍
- Codeforces 842B Gleb And Pizza【几何,水】
- arm_linux_device_mem内存映射
- IntelliJ IDEA 源值1.5已过时,将在未来所有版本中删除
- C++关于Union使用的部分总结
热门文章
- Ubunutu的apt-get软件下载工具的国内镜像源
- [2007年NOIP普及组] 纪念品分组
- react常见bug - 查询条件变化,但page未重置为1
- 【APT】APT-C-41下载器组件样本分析
- 开始 go
- Debug -->; python中的True False 0 1
- What is the Best Python IDE for Data Science?
- PTA1003 我要通过! (20 分)
- UI自动化之【maven+selenium环境搭建】
- 第14章 身份验证:使用Identity将用户添加到应用程序(ASP.NET Core in Action, 2nd Edition)