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

Class IX IT notes: Part A, Unit 1, Session 3.

 IT notes class 9 Part A Unit 1: COMMUNICATION SKILLS session 3: VISUAL AND WRITTEN METHODS OF COMMUNICATION Q1. What is Visual Communicatio...