A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a C++ program to reverse a given array of integers and length 5
Q:

Write a C++ program to reverse a given array of integers and length 5

0

Write a C++ program to reverse a given array of integers and length 5

Sample Output:

Original array:
0 10 20 30 40
Reverse array:
40 30 20 10 0

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
using namespace std;

int *test(int nums[]) {
   static int  r_array[] = {nums[4], nums[3], nums[2], nums[1], nums[0] }; 
    return r_array;
}

int main () {
   // a pointer to an int.
   int *p;
   int nums[] = {0, 10, 20, 30, 40};	
   
   int arr_length = sizeof(nums) / sizeof(nums[0]);
   cout << "Original array: " << endl;   
   for ( int i = 0; i < arr_length; i++ ) {    
      cout << nums[i] << " ";
   }
   
   p = test(nums);
   cout << "\nReverse array: " << endl;
   for ( int i = 0; i < arr_length; i++ ) {
      cout << *(p + i) << " ";
   }

   return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now