memset 函数基本含义讲解

文献来源:网站http://en.cppreference.com

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).

填充内存块

用指定的值(一个无符号数据类型)来设置指定指针ptr的前num个字节的内存块

参数含义

ptr

Pointer to the block of memory to fill.

ptr:指定指针的内存块来填充

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.

value:设置的值。该值的类型为一个int类型,但这个函数会把这个值转换为无符号的char类型的值来填充内存块

num

Number of bytes to be set to the value.

size_t is an unsigned integral type

num:规定多少个数字个字节来设置value

size_t是一个无符号的完整的字节

该函数可以理解为“内存设置”,把一个内存块的前num个字节填充为规定value。

如上图的例子,这个函数把str数组的前六个字节改成了‘-’

该文案仅为作者的自己想法,是网站的粗略翻译,如果有语言不妥,欢迎指出

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值