I'm trying to reverse a string with the Reverse function. If I put size of the output array 10 and give 10 values as input , i give the perfect output. But if i initialize the size of output array with str.size() it gives some garbage value also.
#include<iostream>
#include<string>
using namespace std;
string Reverse(string str)
{
cout<<str.size()<<endl;
char output[str.size()];
int temp = 0;
for(int i = str.length()-1 ; i >= 0 ; i--)
{
output[temp] = str[i];
temp++;
}
return output;
}
int main()
{
char st[100];
cout<<Reverse(gets(st));
return 0;
}