The Memset function exists in the header file <cstring> of C/s + + and is used (typically) to initialize the array. (especially when an array has been used (crossed out))
Format:
-
memset (void *s,int ch,size_t N);
Function Explanation: Replaces the N bytes (typedef unsigned int size_t) in s that follow the current position with CH and returns S.
-
Memset: The function is to populate a block of memory with a given value, which is the fastest way to clear 0 operations on large structures or arrays.
-
--from Baidu Encyclopedia
-
I believe this passage can be understood by everyone. To facilitate understanding of the given example:
1#include <cstdio>2#include <cstring>3 4 intMain () {5 inta[Ten];6Memset (A,0,sizeof(a));7 for(intI=1; i<=9; i++) printf ("%d", A[i]);8 return 0;9}
Run the program and you'll see a line of cute 0 rows standing in front of you.
However, when I was in the brush (water) problem, in order to lazy write for loop I directly use Memset to initialize an array to 1, just like this:
memset (Enode,1,sizeof(enode));
That day reminded me of my fear of being dominated by WA, until I found out that enode after the memset operation in the commissioning period:
Why is it?
Originally, the Memset function initializes a block of memory by Byte, so it cannot be used to initialize an int array to a value other than 0 and-1 (unless the value is the same as high and low). (--from Baidu Encyclopedia)
As for Memset's memory management involving pointers, it is not a category that our earth people understand--even the pointers themselves are not for human use.
Come and read with me: Do not touch the hands rp++!!
C + + memset usage