Printf MCQ 6 : Constant Number Instead of Variable in Printf
Printf Multiple Choice Questions : Constant Number Instead of Variable in Printf
Predict the Output of the Following Program if Given Things are -
- Two Variables are declared .
- Two Variables are initialized
#include<stdio.h> void main() { int input1 = 10,input2 = 20; printf("%d %d",100); }
Options :
- 100 20
- Garbage 20
- 20 10
- Garbage 0
[toggle title=”Output”]100 20[/toggle]
Switch to Printf MCQ Home : Click Here
How and Why ?
- Undefined Behavior of Printf
- Click Here to See All Observation of Undefined Behavior
- Here First %d <—> 100
- Second %d <—> Latest Initialized Variable
What will Happen If Declaration Line is Replaced by This Line ?
int input1 = 20,input2;
Output :
100 20
Why ?
- As Explained Above Here First %d <—> 100
- But Second %d Corresponds to Latest Initialized Variable which is input1 = 20