memset()函数 用于初始化与清空数组

 memset()函数原型是extern void *memset(void *buffer, int c, int count)        buffer:为指针或是数组,

              c:是赋给buffer的值,

       count:是buffer的长度.


       这个函数在socket中多用于清空数组.如:原型是memset(buffer, 0, sizeof(buffer))

       Memset 用来对一段内存空间全部设置为某个字符,一般用在对定义的字符串进行初始化为‘ ’或‘/0’;

      例:char a[100];memset(a, '/0', sizeof(a));

    memset可以方便的清空一个结构类型的变量或数组。

如:

struct sample_struct
{
char csName[16];
int iSeq;
int iType;
};

猜你喜欢

转载自blog.csdn.net/m0_37362454/article/details/80999497