what could be the output of the following program.
int main()
{
char a[] = "www.neentech.blogspot.com";
char *p = a;
printf("%s",
p + p[5] - p[13]);
getch();
return 0;
}
Ans: It will display the below output
.neentech.blogspot.com
Array addition and subtraction |
Explanation: From the Statement
p + p[5] – p[13], p points to address of array a . And p[5] contains/holds character ‘e’
and p[13] holds character ‘b’. So the final statement will be p + ’e’ – ‘b’ ==> p + 101 – 98 (here 'e' equals to decimal 101 & 'b' equals to Decimal 98) ==> p+3 ==> will give the address
location of a[3]. So it will start
printing the string from a[3].
Click here for
more C Faq