多重指针--函数外申请动态内存

一、申请动态内存函数 int apply_memory(const char **pcDesAddr, const int len):

/*************************************************
  Function:    	int apply_memory(const char **pcDesAddr, const int len)
  Description:	申请动态内存
  Input:        len:申请内存大小
  Output:      	**pcDesAddr:动态内存地址
  Return:		-1:失败
                0:成功
*************************************************/
int apply_memory(const char **pcDesAddr, const unsigned int len)
{
	if (!(*pcDesAddr = (char *)malloc(len)))
	{
		printf("Apply [%d] memory FAIL!\n");
		return -1;
	}
	return 0;
}

输入:

1、const unsigned int len:函数需要申请动态内存大小;

输出:

1、const char **pcDesAddr:动态内存首地址;

    char** 是一个指向char*的指针。在函数中如果要对一个参数char *申请空间,同时要在函数外面使用。需要传递char**,否则申请的空间无法在函数外面使用,但申请的空间仍会在,造成空间泄露。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值