Printf() Quiz in C Set-2

Printf() Quiz in C Set-2 | The printf() function in C programming language is used for output formatting. It is used to display information required by the user and also prints the value of the variables.

It formats the output, like the width of the output, the sign of the output e.t.c. We will learn those formatting using printf() C.

Printf() Quiz in C

Find the output of the programs given in printf Quiz in C Set-2

Q1) Find the output of the given C program.

#include<stdio.h>
int main()
{
  printf("%d+%d=%d",1,2,3);
  return 0;
}

a) 123
b) 1+2=3
c) 1+2=garbage_value
d) garbage_value + garbage_value = garbage_value


Ans:- b) 1+2=3

Q2) Find the output of the given C program.

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

a) 1+2=garbage_value
b) garbage_value + garbage_value = garbage_value
c) 123
d) 1+2=3


Ans:- a) 1+2=garbage_value

Q3) Find the output of the given C program.

#include<stdio.h>
int main()
{
  printf("%d+%d=%d",1,2,3,4);
  return 0;
}

a) garbage_value + garbage_value = garbage_value
b) 123
c) 1+2=3
d) 1+2=garbage_value


Ans:- c) 1+2=3

Q4) Find the output of the given C program.

#include<stdio.h>
int main()
{
  printf("%d+%d=%d",'1','2','3');
  return 0;
}

a) 49+50=51
b) None of these
c) error
d) 1+2=3


Ans:- a) 49+50=51

Q5) Find the output of the given C program.

#include<stdio.h>
int main()
{
  printf("%c+%c=%c",'1','2','3');
  return 0;
}

a) 1+2=3
b) None of these
c) 49+50=51
d) error


Ans:- a) 1+2=3

Q6) Find the output of the given C program.

#include<stdio.h>
int main()
{
  printf("%c+%c=%c",65,66,67);
  return 0;
}

a) A+B=C
b) error
c) None of these
d) 65+66=67


Ans:- a) A+B=C

Q7) Find the output of the given C program.

#include<stdio.h>
int main()
{
  printf("%c+%c=%c",a,b,c);
  return 0;
}

a) 65+66=67
b) A+B=C
c) None of these
d) error


Ans:- d) error

The compiler creates a, b, and c as variables not as constants. The variables must be declared first before using it in the program.


Q8) Find the output of the given C program.

#include<stdio.h>
int main()
{
  printf("%d+%d=%d",'a','b','a'+'b');
  return 0;
}

a) a + b = a+b
b) a + b = c
c) 97+98=195
d) error


Ans:- c) 97+98=195

Q9) Find the output of the given C program.

#include<stdio.h>
int main()
{
  printf("%d+%d=%D",1,2,3);
  return 0;
}

a) None of these
b) error
c) 1+2=%D
d) 1+2=3


Ans:- c) 1+2=%D

C language is case sensitive, %d, and %D are different. %d is conversion specifier but %D is treated as simple text or string.


Q10) Find the output of the given C program.

#include<stdio.h>
int main()
{
  printf("%d%%d=%d",9,2,9%2);
  return 0;
}

a) 9%2 = 1
b) 9%d = 2
c) 9%d = 1
a) 9%2 = 2


Ans:- b) 9%d = 2

In C language, to print ‘%’ we use escape character %% So, in this program %%d converted to string %d. The 9 will be used for the first %d, so before assignment operator, it will display 9%d. Now, after assignment operator %d is there, since 9 is already used and the next constant is 2. Finally, it gives the output 9%2=2, Note that the last constant (9%2) was never used by the program because there was only two %d to display variable but there are three constants (9, 2, 9%2)

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or you find anything incorrect? Let us know in the comments. Thank you!

2 thoughts on “Printf() Quiz in C Set-2”

  1. Missing choice a for last question. Also while it’s obvious to someone experienced, for question 7, you should specify “the variables must be declared first if you want the error to go away”. The wording might make newbies think that variables aren’t allowed at all for some reason.

Leave a Reply