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();

}

Try looking at it like this:

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

or like this:

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

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

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

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)

Thanks a lot to all of you ............

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.