Which is faster/preferred: memset or for loop to zero out an array of doubles?

If you really care you should try and measure. However the most portable way is using std::fill():

std::fill( array, array + numberOfElements, 0.0 );

Leave a Comment