Question: If I have an array of doubles, such as `static double arr[10];` and I'd like to initialize all of the values in the array to `0`, I do:

```
1 for (int i = 0; i < 10; i++)
2    arr[i] = 0;

```

**My question:**

Is line 2 correct, or do I need to initialize to `0.0`? What's the difference?

Answer: 
There are no uninitialized variables with `static` storage duration. Zero initialized static data is stored in the `BSS` section and data uninitialized in the program is initialized to `0` and then stored in the `BSS` section.

So you are not required to explicitly initiate your **static** array of doubles.

Your code of `arr[i] = 0` is correct since the `int` will be automatically promoted to a `double`.

But I would recommend for better readability, you initialize the array as follows:

```
static double arr[10] = {0.0};

```
A *static* array of doubles with no explicit initializer will automatically be initialized to all-zero at program start. (Technically, a static *anything* with no explicit initializer is automatically initialized to all-zero at program start.) If you need to reinitialize a static array of scalars to all-zero again, or you need to initialize an *automatic* array of scalars to all-zero before using it, the loop you have is correct except that technically the `int` should be `size_t`.

```
for (size_t i = 0; i < n_elements; i++)
    arr[i] = 0;

```

In C, this construct works no matter what the element type of `arr` is; there is no scalar type that cannot be assigned the integer constant `0`. (If you have an array of aggregates you have to do something more verbose.) Also consider

```
memset(arr, 0, n_elements * sizeof(element_type));

```

which works for arrays of aggregates as well. This is technically not required to set all scalar types to their appropriate zero value, but it does do so in practice on all systems you are ever likely to encounter.

The difference between the integer constant `0` and the floating-point constant `0.0` becomes visible if you do something else with them: for instance

```
int    a = 0;    // ok (no conversion)
double b = 0;    // ok (implicit conversion to double)
char*  c = 0;    // ok (implicit conversion to char* null pointer)

int    d = 0.0;  // ok (implicit conversion to int, does not change value)
double e = 0.0;  // ok (no conversion)
char*  f = 0.0;  // error! cannot initialize pointer var with fp constant

int    g = 3.14159; // dubious: value truncated to 3
double h = 3.14159; // ok
char*  i = 3.14159; // error (same as above)

```

clang 3.5 for instance says:

```
test.c:7:7: error: initializing 'char *' with an expression of incompatible type
      'double'
char* f = 0.0;
      ^   ~~~
test.c:9:11: warning: implicit conversion from 'double' to 'int' changes value
      from 3.14159 to 3 [-Wliteral-conversion]
int   g = 3.14159;
      ~   ^~~~~~~
test.c:11:7: error: initializing 'char *' with an expression of incompatible
      type 'double'
char* i = 3.14159;
      ^   ~~~~~~~

```