How to Print an Array in C++? Last Updated : 12 May, 2024 Comments Improve Suggest changes Like Article Like Report Try it on GfG Practice In C++, an array is a fixed-size linear data structure that stores a collection of elements of the same type in contiguous memory locations. In this article, we will learn how to print an array in C++. For Example, Input: array = {10, 20, 30, 40, 50}Output: Array Elements: 10 20 30 40 50Printing Array Elements in C++ To print array elements in C++, we can use a simple for loop to iterate over the elements of the array and print each element while iterating. This allows us to print the whole array without using a single statement for printing single element. C++ Program to Print an Array C++The below program demonstrates how we can use a simple for loop to iterate over the array elements and print each one. C++ // C++ program to print an array #include <iostream> using namespace std; int main() { // Intializing an Array int array[] = { 10, 20, 30, 40, 50 }; // finding size of array int n = sizeof(array) / sizeof(array[0]); // Print the array cout << "Array Elements: "; for (int i = 0; i < n; i++) cout << array[i] << " "; cout << endl; return 0; } OutputArray Elements: 10 20 30 40 50 Time Complexity: O(N), where N is the size of the array.Auxilliary Space: O(1) Note: We can also use range based for loop in C++11 and later to iterate through the array and print each element. Comment More infoAdvertise with us Next Article How to Print an Array in C++? K krahuld77u Follow Improve Article Tags : C++ Programs C++ cpp-array C++ Array Programs CPP Examples +1 More Practice Tags : CPP Similar Reads How to Sort an Array in C++? Sorting an array involves rearranging its elements in a specific order such as from smallest to largest element or from largest to smallest element, etc. In this article, we will learn how to sort an array in C++.Example:Input: arr ={5,4,1,2,3}Output: 1 2 3 4 5Explanation: arr is sorted in increasin 4 min read How to Initialize an Array in C++? In C++, an array is a collection of similar datatypes stored in contiguous memory locations in which each element can be accessed using their indices. In this article, we will learn how to initialize an array in C++. Initializing an Array in C++To initialize an array in C++, we can use the assignmen 2 min read How to Loop Over an Array in C++? In C++, an array is a data structure that stores elements of similar type in contiguous memory locations. We can access the elements of an array using array indexing. In this article, we will learn how to loop over an array in C++. Example: Input: int arr[] = [1, 2, 3, 4, 5] Output: Array Elements: 2 min read How to Resize an Array of Strings in C++? In C++, the array of strings is useful for storing many strings in the same container. Sometimes, we need to change the size of this array. In this article, we will look at how to resize the array of strings in C++. Resize String Array in C++There is no way to directly resize the previously allocate 2 min read How to Declare an Array in C++? In C++, an array is a collection of similar data types in which elements are stored in contiguous memory locations. In this article, we will learn how to declare an array in C++. Declaring an Array in C++In C++, we can declare an array by specifying the type of its elements, followed by the name of 2 min read How to Copy One Array to Another in C++? In C++, arrays are a type of data structure that stores a fixed-size collection of elements of the same type in a contiguous memory location, and sometimes we need to copy the contents of one array to another. In this article, we will learn how to copy one array to another in C++. Example: Input: ar 2 min read How to Initialize a Dynamic Array in C++? In C++, dynamic arrays allow users to allocate memory dynamically. They are useful when the size of the array is not known at compile time. In this article, we will look at how to initialize a dynamic array in C++. Initializing Dynamic Arrays in C++The dynamic arrays can be initialized at the time o 1 min read How to Create an Array of Structs in C++? In C++, a struct is a user-defined data type that allows us to combine data of different types and an array of structs is an array in which each element is of the struct type. In this article, we will learn how to create an array of structs in C++. Creating an Array of Structs in C++To create an arr 2 min read How to Reverse an Array using STL in C++? Reversing an array means rearranging its elements so that the first element becomes the last, the second element becomes the second last, and so on. In this article, we will learn how to reverse an array using STL in C++.The most efficient way to reverse an array using STL is by using reverse() func 2 min read How to Find the Length of an Array in C++? In C++, the length of an array is defined as the total number of elements present in the array. In this article, we will learn how to find the length of an array in C++.The simplest way to find the length of an array is by using the sizeof operator. First calculate the size of the array in bytes and 2 min read Like