Character Pointer working abnormally

void reverse() {
    int i=0,j=0;
    char *str, *revstr;
    cout<<"Enter a string :: ";
    cin>>str;
    while(str[i]!='') { i++; }
    i--;
    while(i>=0) 
    {
       revstr[j]=str[i];
       cout<<"n"<<revstr[j]<<"t"<<j<<"t"<<i;
       j++;
       i--;
    }
    revstr[j]='';
    cout<<"Original String :: "<<str;
    cout<<"Reversed String :: "<<revstr;
}

As you can see this is a simple piece of code to reverse a string in C++. But somehow due to a reason unknown to me, cout<<"Reversed String :: "<<revstr produces nothing. I executed this in Turbo C++ by the way. Is this because of pointers having garbage value or something?


Source: c++

Leave a Reply