C++ Print Array
You can print array elements in C++ using looping statements or foreach statement.
C++ Print Array using While Loop
In this example, we will use C++ While Loop to print array elements.
C++ Program
#include <iostream> using namespace std; int main() { int arr[7] = {25, 63, 74, 69, 81, 65, 68}; int i=0; while (i < 7) { cout << arr[i] << " "; i++; } }
Output
25 63 74 69 81 65 68
C++ Print Array using For Loop
In this example, we will use C++ For Loop to print array elements.
C++ Program
#include <iostream> using namespace std; int main() { int arr[7] = {25, 63, 74, 69, 81, 65, 68}; for (int i=0; i < 7; i++) { cout << arr[i] << " "; } }
Output
25 63 74 69 81 65 68
C++ Print Array using ForEach Statement
In this example, we will use C++ Foreach statement to print array elements.
C++ Program
#include <iostream> using namespace std; int main() { int arr[7] = {25, 63, 74, 69, 81, 65, 68}; for (int element: arr) { cout << element << " "; } }
Output
25 63 74 69 81 65 68
Conclusion
In this C++ Tutorial, we learned how to print array elements using looping statements.