279 views
0 votes
0 votes
What is the output of the following program?
int main ( )
{
char *str = “Gate2015”
printf (“%d”, gradeup (str)) ;
return 0;
}
int gradeup (char *P1)
{
char *P2 = P1 ;
while (*++P1) ;
return (P1 – P2);
}

How P1 points to null and P2 to starting based on that they gave answer as 8

1 Answer

0 votes
0 votes
P1 initially points to base address and and *p2=p1 makes p2 also to point same base address

while(*++p1) will cotinue till it reaches null character and its address say 108 if we assume base address to be 100

so p1-p2 we can perform as both are pointing to same array so (108-100)/1=8

No related questions found