首页 > 代码库 > memset函数

memset函数

memset

接口形式:

void * memset ( void * ptr, int value, size_t num );
用给定的值value填充ptr所指的内存块。
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.
size_t is an unsigned integral type.

Return Value

ptr is returned.


例子:

/* 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函数