void *memset(void *dest, int c, size_t count)
The 3rd argument is the Number of characters or bytes in the array. How would you memset an array of booleans, say bool bArray[11]?
MSDN says: "Security Note - Make sure that the destination buffer has enough room for at least count characters."
//Array declaration
bool arr[10];
//To initialize all the elements to true
memset(arr,1,sizeof(arr));
Similarly, you can initialize all the elements to false, by replacing 1 with 0.
std::fill()
should use memset()
when possible.
std::fill(std::begin(bArray), std::end(bArray), value);
If bArray
is a pointer, then the following should be used:
std::fill(bArray, bArray + arraySize, value);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With