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


void main()
  char c[]="GATE2011";
  char *p=c;


Recommended Answers

All 4 Replies

Try looking at it like this:

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

or like this:


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, learning, and sharing knowledge.