Skip to content
Related Articles

Related Articles

C Quiz – 103 | Question 3
  • Last Updated : 05 Oct, 2015

What’s going to happen when we compile and run the following C program snippet?




#include "stdio.h"
int main()
{
 int a = 10;
  
 printf("=%d %d=",(a+1));
  
 return 0;
}


(A) =11 0=
(B) =11 X= where X would depend on Compiler implementation
(C) Undefined behaviour
(D) Compiler Error due to missing argument for second %d


Answer: (C)

Explanation: In the context of printf() and fprintf(), as per C standard C11 clause 7.21.6.1,
“If there are insufficient arguments for the format, the behavior is undefined. If the format is exhausted while arguments remain, the excess arguments are evaluated (as always) but are otherwise ignored.”
Some implementation can choose to print =10 0= while other implementations can choose to print =11 X=. That’s why the output of above program varies depending on the compiler and platform. Hence, correct answer is C).

Quiz of this Question

Attention reader! Don’t stop learning now. Get hold of all the important C++ Foundation and STL concepts with the C++ Foundation and STL courses at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :