数组的初始化与memset的注意事项

本文探讨了在编程中使用memset初始化数组的细节,通过示例`memset(count_3,1,26)`解释了如何低位扩充高位,形成32位数值0x01010101,即16843009。" 125301448,13903409,three.js实现3D天空效果,"['javascript', '3D开发', '图形学']
摘要由CSDN通过智能技术生成
    如果全部初始化为0,可以int count[26]={0};这样初始化为26个0
    如果int count[26]={2015};,则只有第一个按照给定值初始化,其余初始化为0
    这种方法对于double数组同样适用
    对char数组也适用,只是第一个元素按照给定值初始化外,其余的初始化为小写字母a
    这种方法并不具有普适性,因为编译器的差异会导致不一样的结果,比如可能会有
    个别编译器对局部数组不初始化,输出随机值。
    因此尽量使用memset对数组进行初始化
    void * memset ( void * ptr, int value, size_t num ); <cstring>
    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.
    Return Value
    ptr is returned. <
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值