How to fills all the elements of fixed size array with the same value of in C++

1 Answer

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

int main()
{
    std::array<int, 5> arr = { 1, 2, 3, 4, 5 };
    
    arr.fill(3);
    
	for (int i = 0; i < arr.size() ; i++) {
        std::cout << arr[i] << "\n";
    }

    return 0;
}




/*
run:

3
3
3
3
3

*/

 



answered Dec 4, 2020 by avibootz

Related questions

1 answer 171 views
1 answer 208 views
1 answer 245 views
1 answer 157 views
1 answer 266 views
1 answer 173 views
173 views asked Dec 5, 2020 by avibootz
...