memset初始化详解

本文详细解析了C++中memset函数用于初始化数组的工作原理,包括初始化char和int类型数组的特殊情况,以及如何初始化为1。此外,还探讨了在算法竞赛中memset的使用策略,特别是在初始化大量数据时避免溢出问题的重要性。
摘要由CSDN通过智能技术生成

参考文档

Function
void * memset ( void * ptr, int value, size_t num );
Fill block of memory
Sets the first num bytes of the block of memory pointed by ptr to the specified value (interpreted as an unsigned char).


Parameters
ptr
Pointer to the block of memory to fill.
value
Value to be set. The value is passed as an int, but the function fills the block of memory using the unsigned char conversion of this value.
num
Number of bytes to be set to the value.
size_t is an unsigned integral type.

参数含义

参数名称 参数含义
ptr 内存块的地址(起始位置)
value 要填充的内容
num 要填充的内存块的大小
  • 7
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值