Firstly, a memset takes a size in bytes, not the number of elements in an array, because it cannot know how large each element is. You need to use sizeof to get the size in bytes of the array and instead specify memset :
memset(a, 99, sizeof(a));
However, in C ++, prefer std::fill because it is type safe, more flexible, and can sometimes be more efficient:
std::fill(begin(a), end(a), 99);
The second and more pressing problem is that in this case memset and fill have different behavior, so you have to decide what you want: memset will set each byte to 99, while fill will set each element (each int in your case ) to 99. If you need an array full of integers equal to 99, use fill , as I showed. If you want each byte to be set to 99, I would recommend using int* in char* and using fill memset instead, but memset will work too.
source share