0

The output is 2011. Can anyone plz tell me how it is so ????

#include<stdio.h>
#include<conio.h>

void main()
{
  char c[]="GATE2011";
  char *p=c;
  clrscr();
  printf("%s",p+p[3]-p[1]);
  getch();

}
3
Contributors
4
Replies
7
Views
6 Years
Discussion Span
Last Post by ram619
1

Try looking at it like this:

printf("%s",p + (p[3] - p[1]));

or like this:

printf("%s",&p[4]);

Edited by gerard4143: n/a

1

If your still having problems try looking at the problem like this:

printf("%s",p + ('E' - 'A'));
0

The ascii value of E is 69 and A is 65
so more or less the its like

printf("%s",p + 69-65);

when simplified it will look like

printf("%s",p + 4);

this will print out the characters from 2 up to 1 (2011)

Edited by zeroliken: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.