Answers for "reverse print array elements c++"

C++
0

printing an array backwards in c++

#include <iostream>
 
// Print contents of an array in reverse order in C++
// using array indices
int main()
{
    int arr[] = { 10, 20, 30, 40 };
    size_t n = sizeof(arr)/sizeof(arr[0]);
 
    // iterate backwards over the elements of an array
    for (int i = n - 1; i >= 0; i--) {
        std::cout << arr[i] << ' ';
    }
 
    return 0;
}
Posted by: Guest on March-09-2021

Code answers related to "reverse print array elements c++"

Browse Popular Code Answers by Language