Click here to Skip to main content
16,004,453 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
#include <iostream>
using namespace std;

void reverseArray(string arr[]) //can writhe length parameter also
{
    int j=0;
    string revArray[arr->length()];
    for(int i=arr->length(); i>0; i--)
    {

        revArray[j]=arr[i];
        j++;
    }
    for(int i=0; i<revArray->length(); i++)
    {
        cout<<revArray[i]<<endl;
    }
}

int main()
{
    string arr[5]={"Audi"};
    reverseArray(arr);
}


What I have tried:

I want the program to output the reverse of "Audi", but it does not output anything.
Posted
Updated 22-Oct-17 3:03am

1 solution

Quote:
string arr[5]={"Audi"};

You declared (and defined) an array of strings. See the array content running the following code:
C++
for (int n=0; n<5; ++n)
{
  cout << "arr[" << n << "] =\"" << arr[n] << "\"" << endl;
}

Then your code works on array items instead of reversing, as requested, the string of item 0.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900