C - Data Types - Discussion

You Are Here :: Home > C > Data Types - Discussion

 



Q.

#include

main()
{
char s[]={'a','b','c','\n','c','\0'};
char *p,*str,*str1;
p=&s[3];
str=p;
str1=s;
printf("%d",++*p + ++*str1-32);
}

A. 37 B. 47
C. 57 D. 77

Answer: Option D
Explaination:

p is pointing to character '\n'. str1 is pointing to character 'a' ++*p. "p is pointing to '\n' and that is incremented by one." the ASCII value of '\n' is 10, which is then incremented to 11. The value of ++*p is 11. ++*str1, str1 is pointing to 'a' that is incremented by 1 and it becomes 'b'. ASCII value of 'b' is 98.

Now performing (11 + 98 - 32), we get 77("M");
So we get the output 77 :: "M" (Ascii is 77).



Discussion

Your Comments Goes here...
NameDiscussion