解释memset(a,‘0‘,sizeof(a)); 的意思

memset:作用是在一段内存块中填充某个给定的值,它是对较大的结构体或数组进行清零操作的一种最快方法。

这条语句是把a中所有字节换做字符“0”,常用来对指针或字符串的初始化。

函数原型如下:
void *memset(void *s, int ch, size_t n);
函数解释:将s中前n个字节 (typedef unsigned int size_t)用 ch 替换并返回 s将ch设置为0
综上可知
原型:extern void *memset(void *buffer, int c, int count);

用法:#include <string.h>

功能:把buffer所指内存区域的前count个字节设置成字符c。

说明:返回指向buffer的指针。

举例:

// memset.c

  #include <syslib.h>
  #include <string.h>

  main()
  {
    char *s="Golden Global View";
   
    clrscr();
   
    memset(s,'G',6);
    printf("%s",s);

    getchar();
    return 0;
  }

猜你喜欢

转载自blog.csdn.net/weixin_41454036/article/details/108363447