如果全部初始化为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. <
如果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. <