#include#include int main() { std::array arr; arr.fill(10); // Fill the array with value 10 for (auto val : arr) { std::cout << val << " "; } return 0; }
#includeOutput: `-1 10 10 10 -1` In both examples, the `fill` function is used to assign a specific value to all the elements in the array. The first example fills the entire array with value 10, whereas the second example fills only a portion of the array with the same value. The package library used is#include int main() { std::array arr {1, 2, 3, 4, 5}; arr.fill(-1); // Fill the entire array with value -1 arr.fill(10, 1, 4); // Fill only elements from index 1 to 3 with value 10 for (auto val : arr) { std::cout << val << " "; } return 0; }