How to initialize all the elements of an array object with the same number in C++

1 Answer

0 votes
#include <iostream>
#include <array>

int main ()
{
    std::array<int, 7> arr;

    arr.fill(5);

    for (int &n : arr) { std::cout << n << ", "; }
    
    return 0;
}
 
 
 
/*
run:
 
5, 5, 5, 5, 5, 5, 5, 
  
*/

 



answered Jul 28, 2020 by avibootz

Related questions

...