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

Python script to show Laptop Battery Percentage

Source:  https://www.geeksforgeeks.org/python-script-to-show-laptop-battery-percentage/ # python script showing battery details  import psut...