C++初阶:浅识内存管理

目录

一、知识点考察

二、C++内存管理方式

1.new/delete操作内置类型

2.new/delete操作自定义类型


一、知识点考察

int globalVar = 1;
static int staticGlobalVar = 1;
void Test()
{
	static int staticVar = 1;
	int localVar = 1;
	int num1[10] = { 1, 2, 3, 4 };
	char char2[] = "abcd";
	const char* pChar3 = "abcd";
	int* ptr1 = (int*)malloc(sizeof(int) * 4);
	int* ptr2 = (int*)calloc(4, sizeof(int));
	int* ptr3 = (int*)realloc(ptr2, sizeof(int) * 4);
	free(ptr1);
	free(ptr3);
}

1. 选择题:
选项 : A.栈  B.堆  C.数据段(静态区)  D.代码段(常量区)
globalVar在哪里?____   staticGlobalVar在哪里?____
staticVar在哪里?____   localVar在哪里?____
num1 在哪里?____ 
ptr1在哪里?____              *ptr1在哪里?____
char2在哪里?____           *char2在哪里?___
pChar3在哪里?____        *pChar3在哪里?____

2. 填空题:
sizeof(num1) = ____;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值