Monday, July 2, 2018

C program to Reversing String without using array

//REVERSING A KNOWN STRING without using ARRAYs

/*If you use sizeof()then a char *str and char str[] will return different answers.
char str[] will return the length of the string(including the string terminator)
while char *str will return the size of the pointer(differs as per compiler).


*/

#include<stdio.h>
#include<string.h>
int main()
{

    char *c= "Hello world";
    int n=0,i=0;
    while(*(c+i)!='\0'){
        n++;
        i++;

    }

    for(int i=(n-1);i>=0;i--)
    {
        printf("%c",*(c+i));
    }
return 0;
}

No comments:

Post a Comment

Sacred Thought

5 May 2024 Hari Om Verse 50-51, chapter two:  In this chapter two Shree krishna explains a simple way of living. Free from desires and void ...