Right Click to Search

Saturday, March 6, 2025

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 :
  1. 100 20
  2. Garbage 20
  3. 20 10
  4. Garbage 0

Output :

Switch to Printf MCQ Home :  Click Here

How and Why ?
  1. Undefined Behavior of Printf
  2. Click Here to See All Observation of Undefined Behavior 
  3. Here First %d <---> 100
  4.     Second %d <---> Latest Initialized Variable
What will Happen If Declaration Line is Replaced by This Line ?
int input1 = 10,input2;
Output :
100 10
Why ?
  1. As Explained Above Here First %d <---> 100 
  2. But Second %d Corresponds to Latest Initialized Variable which is input1 = 10

  Bookmark & Share

Tags / Keywords : |

Stumble
Delicious
Technorati
Twitter
Facebook

0 Comments:

Post a Comment

Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email

 

Learn C Programming Copyright © 2010 LKart Theme is Designed by Lasantha, Free Blogger Templates