Reverse a String without using strrev (Pointer Approach) in C++

C++ Program to reverse a String without using strrev (Pointer Approach)

Source code :

#include <iostream>
#include <string.h>
#include <stdlib.h>

using namespace std;

int main(){
    
    const char *original = "CODE";
    
    int length = strlen(original);
    char *reversed = (char*) malloc( length * sizeof(char));
    int j=0;
    
    for( int i = length - 1 ; i >= 0 ; i-- ){
        reversed[i] = original[j];
        j++;
    }
    
    cout<<"Original String : "<< original<<endl;
    cout<<"Reversed String : "<< reversed;

    return 0;

}

Output :

Original String : CODE
Reversed String : EDOC

Output :


                

Comments :