# 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-4 | This quiz is on String length using printf() and printf() inside printf() in C Programming language. 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
In C, there are many predefined library functions are available for input and output operations. These functions are collectively called standard input-output library functions, and all these functions are available in stdio.h
header file.
Note:- We can write printf() inside printf(). Execution will be inside to the outside of printf(). First inside printf() will executed and then outside printf(). The printing order will be right to left.
If you finding difficulties to solve these questions then first you should learn these:-
Printf() Quiz in C
Q1) Find the output of the given C program.
#include<stdio.h>
int main()
{
int a = printf("Hello");
printf("\t %d",a);
return 0;
}
a) Hello 6
b) error
c) Hello 5
d) Garbage value
View Answer
Answer:- c) Hello 5The printf() returns the length(integer) of string. In string ‘\0’ is not counted as a character. Here “Hello” has 5 characters so printf display Hello to the screen and returns 5 to the variable a.
Q2) Find the output of the given C program.
#include<stdio.h>
int main()
{
int n=9988;
printf("%d", printf("%d", printf("%d", n) ) );
return 0;
}
a) 998899889988
b) 9988
c) 998841
d) Compile time error
View Answer
Answer:- c) 998841Innermost printf(“%d”, 9988) display 9988 returns the number of digits (in this case 4 due to 9988) to the second inner printf. Now,
printf(“%d”, printf(“%d”, 4));
Second inner printf display 4 and return number of digits (in this case 1 for 4) to the outer printf. Now,
printf(“%d”, 1);
The final output is:- 998841
Q3) Can we find string length without using a loop or strlen()?
a) No
b) Yes
View Answer
Answer:- b) YesUsing printf() function we can find the length of any string without using loop or strlen().
Q4) Find the output of the given C program.
#include<stdio.h>
int main()
{
printf("I miss you", printf("buddy "));
return 0;
}
a) I miss you
b) buddy
c) buddy I miss you
d) I miss you buddy
View Answer
Answer:- c) buddy I miss youbuddy I miss you; The innermost print() function, printf(“buddy “) will execute and display “buddy “. Now, printf(“I miss you”, 5);
The next printf() will execute and print “I miss you”.
Q5) Find the output of the given C program.
#include<stdio.h>
int main()
{
printf("\t Spiderman-%d",printf("Coming"));
return 0;
}
a) Coming
b) Coming Spiderman-5
c) Coming Spiderman-7
d) Coming Spiderman-6
View Answer
Answer:- d) Coming Spiderman-6printf(“Coming”) display Coming and it has 6 charaters. Outer printf() display this 6 using conversion specifier %d.
Q6) Find the output of the given C program.
#include<stdio.h>
int main()
{
printf("John Wick-%d",printf("The Lion King\t"));
return 0;
}
a) The Lion King John Wick-11
b) The Lion King John Wick-14
c) The Lion King John Wick-15
d) The Lion King John Wick-13
View Answer
Answer:- b) The Lion King John Wick-14printf(“The Lion King\t”) display “The Lion King” and it has 14 characters, blank space is a special character and ‘\t’ is an escape character.
If 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!
There must be a more space between hello and 5 in question 1