smilenow 17 Newbie Poster

Not possible.

p[3] == '2' == 50 (see any ascii chart for values)

p[1] == 'a' == 97

Therefore: 50 - 97 == -47, which is a negative value, so the result of p+p[3]-p[1] == 47 bytes before p.

p[3]=e[ascii code=69]and p[1]=a[ascii code=65]
therefore 69-65=4 which is a+ve value makes ponter p move ahead 4 bytes

Ancient Dragon commented: right +17
smilenow 17 Newbie Poster

I GOT IT... printf("%s",p+p[3]+p[1])
here p is a pointer pointing to the string so it will contain the base address of "gate 2011"
p[3]=e [ascii code=69] and
p[1]=a [ascii code=65]
and p[3]-p[1]=69-65=4
and p+4 means incrementing p by 4,pointer p will now point to 2
and when we print the pointer with specifier %s it prints the string with base address starting at p+4.
hence output is 2011...

smilenow 17 Newbie Poster

the answer is 2011

#include<stdio.h>
void main()
{
    char c[]="gate2011";
    char *p=c;
    printf("%s",p+p[3]-p[1]);
    getch();
}

But really i cannot find out that how did it came.printing p[3]or for any i palone does not give any thing except garbage value ,on the other hand printing p gives gate2011.
can anyone explain?plzzz

its p+p[3]-p[1],not p+p[3]+p[1],hence 2011 is the output...

smilenow 17 Newbie Poster

I doubt "GATE2001" is something what can be put in a char, for example.

y? sure it char be,provided it is an array of char....(array of char is string...remember??)

smilenow 17 Newbie Poster

the answer is 2011

#include<stdio.h>
void main()
{
    char c[]="gate2011";
    char *p=c;
    printf("%s",p+p[3]+p[1]);
    getch();
}

But really i cannot find out that how did it came.printing p[3]or for any i palone does not give any thing except garbage value ,on the other hand printing p gives gate2011.
can anyone explain?plzzz