![]() |
In C++, arrays are fixed-size containers that store elements of the same data type. Empty an array means removing all elements from it. In this article, we will see how to empty an array in C++. Example: Input: myArray = { 1, 8, 2, 9, 1, 5, 6 } Output: myArray = { 0, 0, 0, 0, 0, 0, 0 } Clear an Array in C++In C++, there is no direct function to empty an array, but we can achieve this by using the std:: Syntax of std::fill()std::fill (arr, arr+n, defaultValue);
Here,
C++ Program to Empty an ArrayThe below program demonstrates how we can empty an array in C++ using the C++
Output
Original array: 10 20 30 40 50 Array after emptying: 0 0 0 0 0 Time Complexity: O(N), where N is the size of the array.
|
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |