c++ memset

void * memset ( void * ptr, int value, size_t num );
填充内存块
将ptr指向的内存块的前num个字节设置为指定值(解释为unsigned char)。

  • 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.(要设置的值。该值作为int传递,但该函数使用该值的无符号字符转换来填充内存块。)
  • num
    Number of bytes to be set to the value.
    size_t is an unsigned integral type.(要设置为值的字节数。
    size_t是无符号整数类型。
    )
/* 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;
}

------ every programmer should know memset!

link

posted @ 2022-08-19 22:46  luoganttcc  阅读(12)  评论(0)    收藏  举报