Right Click to Search

Sunday, March 7, 2025

Printf MCQ 7 : printf(1+"%d");



Printf Multiple Choice Questions  : printf(1+"%d");

Question : Guess the output of Program
#include<stdio.h>
void main()
{
printf(1+"%d");
printf(1+"%c");
}
Options :
  1. Garbage
  2. dc
  3. cd
  4. %d%c

Output :

Switch to Printf MCQ Home :  Click Here

How and Why ?
  1. Printf Returns the Length of String specified in Double Quotes
  2. Consider first printf , Length of String specified in first printf i.e "%d" is 2
  3. It starts printing the String Skipping the number of Characters specified before '+' sign
  4. printf(1+"%d") skips "%" character and only prints 'd' as output.
  5. Similarly printf(1+"PRITESH")  prints "RITESH" skipping first "P".
  6. Similarly printf(2+"PRITESH")  prints "ITESH" skipping 2 characters "PR".

Note : 
  1. Operation is similar as Substring Operation
  2. While writing such Statement , Variable is not taken into Consideration .
  3. Confused ?
#include<stdio.h>
void main()
{
int var=10;
printf(1+"%d",var);
}
  1. Above statement also prints "d" as output. i.e Variable is Simply Neglected by Compiler.

  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