53. What will be the output of following code :
// Assume all header files are included
main()
{
char p[ ]="%d\n";
p[1] = 'c';
printf(p,65);
}
A. A
B. 0
C. B
D. Runtime Error
View Answer & Explanation
Ans. a
Explanation : Due to the assignment p[1] = ‘c’ the string becomes, “%c\n”. Since this string becomes the format string for printf and ASCII value of 65 is ‘A’, the same gets printed.
54. What will be the output of following code :
// Assume all header files are included
main()
{
while (strcmp(“some”,”some\0”))
printf(“Strings are not equal\n”);
}
A. 1
B. No output
C. 0
D. Runtime Error
View Answer & Explanation
Ans. b
Explanation :
Ending the string constant with \0 explicitly makes no difference. So “some” and “some\0” are equivalent. So, strcmp returns 0 (false) hence breaking out of the while loop.
