How to memset an array of bools?

void *memset(void *dest, int c, size_t count)

The third argument is the number of characters or bytes in the array. How would you take an array of boolean elements, say bool bArray [11]?

MSDN says: "Security note - make sure that the target buffer has enough space to at least match characters."

+5
source share
4 answers

std::fill()should use memset()whenever possible.

std::fill(std::begin(bArray), std::end(bArray), value);
+16
source
memset(buffer_start, value, sizeof(bool) * number_of_bools);
+4
source

11 bool, . true, memset:

const int N = 11;
bool arr[N];
memset(&arr, 1, sizeof(bool) * N);
0
//Array declaration
bool arr[10];

//To initialize all the elements to true

memset(arr,1,sizeof(arr));

, false, 1 0.

0

All Articles