Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using memset() in double type array

Tags:

c++

I want to set all the index value to -1 in a double array.
Here is my code :

double dp[505];
memset(dp,-1,sizeof(dp));
cout<<dp[0]<<"\n";

But it is showing nan when i try to print its value.

What does nan mean? Is it possible to use memset() in double array?

like image 331
Ali Akber Avatar asked Oct 17 '25 08:10

Ali Akber


1 Answers

In C++, using header <algorithm>, you can write:

double initValue = -1;
std::fill_n(dp, 505, initValue);

memsetting a double array with a non-double value won't work.

like image 105
erenon Avatar answered Oct 19 '25 22:10

erenon