Question:C program to reverse a string using pointers 

Answer 
#include<stdio.h>
int main(){
    char str[50];
    char rev[50];
    char *sptr = str;
    char *rptr = rev;
    int i=-1;

    printf("Enter any string : ");
    scanf("%s",str);
   
    while(*sptr){
     sptr++;
     i++;
    }

    while(i>=0){
     sptr--;
     *rptr = *sptr;
     rptr++;
     --i;
    }

    *rptr='\0';
  
    printf("Reverse of string is : %s",rev);
  
    return 0;
}
Sample output: Enter any string : Pointer Reverse of string is : retnioP 

+ ExplanationNot Moderated
+ Report
Total Preview: 778
C program to reverse a string using pointers
Copyright © 2024. Powered by Intellect Software Ltd