forward from:
- The use of C/C++ fill () https://blog.csdn.net/weixin_43826242/article/details/90607516)
- C language: memset function and fill function
1.memset
Usage: can only be initialized to two values of 0 or -1
#include <cstring>
memset(a, 0, sizeof(a));
memset(a, -1, sizeof(a));
2.fill
Usage: You can use any value to fill a fixed interval
int a[10002];
fill(a, a+1000, 1);
fill(a, a+50, 123);
fill() function parameters: fill(first,last,val);
// first is the first iterator of the container, last is the last iterator of the container, and val is the value to be replaced.
For example:
int a[200];
fill(a, a+100, 1);12
Note: In
fill(), its principle is to assign that piece of cell to the specified value, that is to say, any value can be
memset(), which means that the content of each byte in a block of memory pointed to by s All set to the ASCII value specified by ch, namely 0, 1