Set initializing value for all elements of an array

Is there a way to set an initializing value for every element in an array?
I have a type int array and need a way to set every value to 0. How can this be done?
Like this:
vector<int> vec(size,0);
you can also do it like.

 
int array[10] = {0};


this seems to work for me with 0, but other values will assign the first value then the rest zero (though that may be Devcpp specific)
Last edited on
It's not specific to Dev-C++ (which is just an IDE - you mean GCC/MinGW).
The elements of the array you provide no initializers for are always default-initialized in this case.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;

int main () {

const int n = 10;
int v[n]={};
int i;

for (i = 0; i < n; i++)
      cout<<v[i]<<endl;

cin.get(); cin.get();
return 0;
}


i think this should help :)
Topic archived. No new replies allowed.