if you want 1 value at very index you can do this by
int arr[5] = {1,1,1,1,1}; or
int arr[5];
arr[0] = 1;
arr[1] = 1;
arr[2] = 1;
arr[3] = 1;
arr[4] = 1;
otherwise if you write arr[5] = {1}; only first index will have value 1 rest will be assigned zero automatically like this {1,0,0,0,0}
or #include <iostream>
using namespace std;
int main()
{
int arr[5];
memset(arr, 1, sizeof(arr));
cout << arr;
return 0;
}
so type this code this memset function will fill all the index with value 1 by writing it only once.
hope this answer helps you.
Edited, try this code snippet working perfectly fine
#include <iostream>
#include <array>
int main () {
std::array<int,5> myarray;
myarray.fill(1);
std::cout << "myarray contains:";
for ( int& x : myarray) { std::cout << ' ' << x; }
std::cout << '\n';
return 0;
}