is memset(ary,0,length) a portable way of inputting zero in double array

Posted by monkeyking on Stack Overflow See other posts from Stack Overflow or by monkeyking
Published on 2010-06-01T08:32:24Z Indexed on 2010/06/01 8:33 UTC
Read the original article Hit count: 258

Filed under:
|
|
|

The following code uses memset to set all the bits to zero

#include <iostream>
#include <cstring>

int main(){
  int length = 5;
  double *array = new double[length];
  memset(array,0,sizeof(double)*length);
  for(int i=0;i<length;i++)
    if(array[i]!=0.0)
      std::cerr<< "not zero in: " <<i <<std::endl;
  return 0;
}

Can I assume that this will work on all platforms?

Does the double datatype always correspond to the ieee-754 standard?

thanks

© Stack Overflow or respective owner

Related posts about c++

Related posts about double