table of Contents
1 bzero
The bzero function is declared as follows:
/* Set N bytes of S to 0. */
extern void bzero (void *__s, size_t __n) __THROW __nonnull ((1));
The meaning is also clearly written in the comments, setting the first n bytes of s to 0.
2、memset
The memset function is declared as follows:
__BEGIN_NAMESPACE_STD
/* Set N bytes of S to C. */
extern void *memset (void *__s, int __c, size_t __n) __THROW __nonnull ((1));
Set the first m bytes to c and return s.
3. Examples
/*================================================================
* Copyright (C) 2021 baichao All rights reserved.
*
* 文件名称:bzero_memset.cpp
* 创 建 者:baichao
* 创建日期:2021年02月01日
* 描 述:
*
================================================================*/
#include <iostream>
#include <string.h>
int main()
{
char a[5] = "aaaa";
char b[5] = "bbbb";
char *s = NULL;
bzero(a,2);
s = (char *)memset(b,'c',2);
std::cout<<"a:"<<a<<std::endl;
std::cout<<"b:"<<b<<std::endl;
std::cout<<"s:"<<s<<std::endl;
return 0;
}
operation result: