Printf() Quiz in C Set-3

Printf() Quiz in C Set-3 | 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.

Recommended Posts:- Output Formatting Using Printf Function in C, Printf() Quiz in C Set-2, Prinf() Quiz in C Set-1

Printf() Quiz in C

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

Q1) Find the output of the given C program.

#include<stdio.h>
int main()
{
  printf("learning"+1);
  return 0;
}

a) learnin
b) earning
c) learning
d) Compile time error


Ans:- b) earning

let the base address of the string “learning” is 1000 then 1000+1 =1001 so printf(“learning”+1) print string from memory address 1001, the first character will be skipped and “earning” will print. Similarly, printf(“learning”+3) will display “rning”, and printf(“learning”+4) will display “ning”.


Q2) Find the output of the given C program.

#include<stdio.h>
int main()
{
  printf(1+"learning"+1);
  return 0;
}

a) learning
b) arning
c) earnin
d) earning


Ans:- b) arning

The printf(“learning”+2) is the same as printf(2+”learning”) and printf(1+”learning”+1). So, the first two characters of string will not be displayed.
Note:- if we try to run this line:- printf(“learning”-1); then compiler gives a warning and doesn’t print anything for this line.


Q3) Find the output of the given C program.

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

a) 1
b) Compile time error
c) d
d) %d


Ans:- c) d

In this program, %d will not be treated as a conversion specifier because of + operator. It is treated as string “%d”. Now, this question is the same as previous question. Due to +1 printf skip the first character and display all other characters. So, here only “d” will be printed. Similarly printf(“%d”+3); gives a warning because in string “%d” only three characters are present.


Q4) Find the output of the given C program.

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

a) 99
b) %d
c) 100
d) d


Ans:- d) d

From the previous question we know that “%d” is a string. Here there is no any conversion specifier for constant 99 so, there is no use of 99. Both lines printf(“%d”+1); and printf(“%d”+1,99); are same and gives output:- d


Q5) Find the output of the given C program.

#include<stdio.h>
int main()
{
  printf("Love"," You");
  return 0;
}

a) Love You
b) Love
c) error
d) You


Ans:- b) Love

In this program, “Love” is default string which will print automatically but to print another string “ You” conversion specifier is required. If we write printf(“Love%s”,” You”); then it will give the output “Love You”.


Q6) Find the output of the given C program.

#include<stdio.h>
int main()
{
  printf("Love"+" You");
  return 0;
}

a) error
b) You
c) Love
d) Love You


Ans:- a) error

invalid operands to binary +


Q7) Find the output of the given C program.

#include<stdio.h>
int main()
{
  printf("I " "Love " "You");
  return 0;
}

a) Love
b) You
c) I
d) I Love You


Ans:- d) I Love You

There is no comma operator to separate them so they all treated as a string.


Q8) Find the output of the given C program.

#include<stdio.h>
int main()
{
  printf("I Want to %s %s","say","something");
  return 0;
}

a) I Want to say something
b) Error
c) I Want to say
d) I Want to


Ans:- a) I Want to say something

Q9) Find the output of the given C program.

#include<stdio.h>
int main()
{
  printf("I Want to %s","say","something");
  return 0;
}

a) Error
b) I Want to say something
c) I Want to say
d) I Want to


Ans:- c) I Want to say

Q10) Find the output of the given C program.

#include<stdio.h>
int main()
{
  printf("I Want to %s","say %s","something");
  return 0;
}

a) I Want to
b) I Want to say
c) I Want to say %s
d) I Want to say something


Ans:- c) I Want to say %s

The “say %s” is a String, here %s won’t be treated as a conversion specifier.


Q11) Find the output of the given C program.

#include<stdio.h>
int main()
{
  printf("I Want to %s %s","say %s","something");
  return 0;
}

a) I Want to say something
b) I Want to say
c) I Want to say %s something
d) I Want to say %s


Ans:- c) I Want to say %s something

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!

Leave a Reply