# C PROGRAMS
C Quiz
➤ Identifiers & Data Types Quiz
➤ Octal Decimal & Hexadecimal
➤ Increment-Decrement Quiz
➤ Relational-Logical Quiz
➤ Arithmetic -Assignment Quiz
➤ Comma Operator Quiz
➤ Sizeof operator Quiz
➤ printf() Quiz Set-1
➤ printf() Quiz Set-2
➤ printf() Quiz Set-3
➤ printf() Quiz Set-4
➤ If statement Quiz in C
➤ If-else statement Quiz
Printf() Quiz in C Set-3 | The printf function in C 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.
If you finding difficulties to solve these questions then first you should learn these:-
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
View Answer
Answer:- b) earninglet 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
View Answer
Answer:- b) arningThe 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
View Answer
Answer:- c) dIn 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
View Answer
Answer:- d) dFrom 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
View Answer
Answer:- b) LoveIn 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
View Answer
Answer:- a) errorinvalid 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
View Answer
Answer:- d) I Love YouThere 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
View Answer
Answer:- a) I Want to say somethingQ9) 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
View Answer
Answer:- c) I Want to sayQ10) 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
View Answer
Answer:- c) I Want to say %sThe “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
View Answer
Answer:- c) I Want to say %s somethingIf you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!