memset
void * memset ( void * ptr, int value, size_t num );
Fill block of memory
Sets the first num bytes of the block of memory pointed byptr 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 theunsigned char conversion of this value.
num
Number of bytes to be set to the value.
Return Value
ptr is returned.
Example
|
1 |
/* memset example */ #include <stdio.h> #include <string.h>
int main () { char str[] = "almost every programmer should know memset!"; memset (str,'-',6); puts (str); return 0; } |
Output:
|
------ every programmer should know memset! |
本文通过一个具体的例子展示了如何使用memset函数来填充内存块,并提供了输出结果的示例。
1009

被折叠的 条评论
为什么被折叠?



