100+ C Programming Output Questions with Explanation
1. What will be the output of following code :
// Assume all header files are included
int main()
{
int a=89;
printf("%c",a);
return 0;
}
A. 89
B. y
C. Y
D. Runtime Error : %c not suitable for integer type.
View Answer & Explanation
Ans. c
Explanation : %c is used for printing the character values, also ASCII code of ‘Y’ is 89.
2. What will be the output of following code :
// Assume all header files are included
int main(void)
{
int cog;
cog=printf("Hey,Welcome")+printf(" to world");
printf("\n%d characters were printed",cog);
return 0;
}
A.
20 characters were printed
B.
Hey,Welcometo world
20 characters were printed
C.
Hey,Welcome to world
20 characters were printed
D.
RunTime Error : Cannot assign string values to integer type.
View Answer & Explanation
Ans. c
Explanation : Option C is correct as at first, message written inside printf() will be printed and then
cog variable holds the length of “Hey,Welcome to world”, will be printed along with ” characters were printed”.