When writing a Data Structure experiment today, an array is dynamically allocated:
Bool * vis = new bool [N];
Then initialize the VIS array:
Memset (VIS, 0, sizeof (VIS ));
As a result, the experiment results are always merged.
The cause is eventually discovered:
VIS is a pointer, so the result of sizeof (VIS) is 4. vis only points to the first address of the memory allocated by the heap. It is different from directly opening a static array (I don't know why), and the pointer size occupies 4, therefore, sizeof (VIS) always returns 4 results.
Therefore, the correct method for initializing the Dynamic Allocation array for memset is:
Type * vis = new type [N]; memset (VIS, 0, N * sizeof (type ));
Later, Baidu went to more details: Exploring the differences between C/C ++ array names and pointers
In short, arrays are also a data structure!