Printf Multiple Choice Questions : printf(1+"%d");
Question : Guess the output of Program
#include<stdio.h>
void main()
{
printf(1+"%d");
printf(1+"%c");
}- Garbage
- dc
- cd
- %d%c
Output :
Switch to Printf MCQ Home : Click Here
How and Why ?
- Printf Returns the Length of String specified in Double Quotes
- Consider first printf , Length of String specified in first printf i.e "%d" is 2
- It starts printing the String Skipping the number of Characters specified before '+' sign
- printf(1+"%d") skips "%" character and only prints 'd' as output.
- Similarly printf(1+"PRITESH") prints "RITESH" skipping first "P".
- Similarly printf(2+"PRITESH") prints "ITESH" skipping 2 characters "PR".
Note :
- Operation is similar as Substring Operation
- While writing such Statement , Variable is not taken into Consideration .
- Confused ?
#include<stdio.h>
void main()
{
int var=10;
printf(1+"%d",var);
}- Above statement also prints "d" as output. i.e Variable is Simply Neglected by Compiler.



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