358 views
0 votes
0 votes
int main(void) {
      char p[20];
      char *s = "Gate015";
      int length = strlen(s);
      int i=0;
      for(i=0;i<length;i++)
        p[i]=s[length-i];
      printf("%s",p);
      return 0;
}

1 Answer

Best answer
4 votes
4 votes
printf("%s",p);

%s prints all characters from the start address given by p till the first occurrence of '\0'; But p[0] = s[length - 0] = '\0'; So, nothing will be printed. 

The code can be corrected by 

for(i=0;i<length;i++)
        p[i]=s[length-i-1];
selected by

Related questions

2 votes
2 votes
1 answer
1
0 votes
0 votes
2 answers
2
shivani2010 asked Apr 18, 2016
515 views
void f(int n){ if(n <= 1){ printf("%d", n); } else{ f(n/2); printf("%d", n%2); } }
4 votes
4 votes
1 answer
3
ritwik_07 asked Jun 10, 2023
436 views
#include<stdio.h #include<string.h #define MAX(x, y) ((x) (y) ? (x) : (y)) int main() { int i = 10, j = 5, k = 0; k = MAX(i++, ++j); printf("%d %d %d", i, j, k); return ...
1 votes
1 votes
2 answers
4
Rajnish Kumar asked Jul 14, 2015
544 views
#define square(x) x*xmain(){int i;i=64/square(4);printf("%d",i);}