
Formatted Input and Output in C
Authored by Harvinder Kaur
Other
University
Used 9+ times

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
10 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What will be the output of the above code if a=123456789245?
123456789245
Compilation error
1234567892
No output
Answer explanation
Using %10d in scanf restricts input to a maximum of 10 digits.
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
The syntax of printf() function is printf(“control string”, variable list) ;
what is the prototype of the control string?
%[flags][.precision][width][length]specifier
%[flags][length][width][.precision]specifier
%[flags][width][.precision][length]specifier
%[flags][.precision][length][width]specifier
Answer explanation
The prototype of control string is %[flags][width][.precision][length]specifier. Each control string must begin with % sign
3.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
What will be the output of the following C code?
char str[] =”Too Good”;
printf(“\n %7s”,str);
Too Good
Too G
Too Go
Too
Answer explanation
The complete string “Too Good” is printed. This is because if data needs more space than specified, then printf overrides the width specified by the user.
4.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
What will be the output of the following C code?
printf(“\n Output: %5d \t %x \t %#x”, 234,234,234);
Output:
234EA0xEA
Output:
00234 EA 0xEA
Output:
234 EA 0xEA
ERROR
Answer explanation
The control character \t is used to provide gap between the words. %5d – the width of the string is set to 5, characters are printed after being padded with blank spaces.%x, %#x is additional specifiers for octal and hexadecimal values.
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Select the right explanation to the given code.
printf(“%*. *f”, 5,4,5700);
the minimum field width has to be 4, the precision is given to be 5, and the value to be displayed is 5700
the minimum field width is 5, the precision is 4, and the value to be displayed is 5700
compile error
run-time error
Answer explanation
The minimum field width and precision specifiers are usually constants. They can also be provided by arguments to printf(). This is done by using * modifier as shown in the given code.
6.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
What will be the output for the given code ?
printf (“\n The number is %07d”,1212);
The number is 0001212
The number is 1212
The number is 1212
The number is 1212000
Answer explanation
0 in the above code is Flags. The number is left-padded with zeros(0) instead of spaces.
7.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
What happens when zero flag is used with left justification?
data is padded with zeros
zero flag is ignored
data is padded with blank spaces
will give error
Answer explanation
Zero flag is not considered when used with left justification because adding zeros after a number changes its value.
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
15 questions
Personal finance 1
Quiz
•
University
10 questions
CCHU5001_Week 3_Quiz
Quiz
•
University
10 questions
IQ #3 MODULE 3 MARKETING MANAGEMENT
Quiz
•
University
10 questions
IIUMSU Quiz!
Quiz
•
University
10 questions
Global Urban Farming
Quiz
•
University
10 questions
La Vida Ambassador Series 1
Quiz
•
University
14 questions
Music History Quiz
Quiz
•
University
15 questions
Harry Potter
Quiz
•
KG - Professional Dev...
Popular Resources on Wayground
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
29 questions
Alg. 1 Section 5.1 Coordinate Plane
Quiz
•
9th Grade
22 questions
fractions
Quiz
•
3rd Grade
11 questions
FOREST Effective communication
Lesson
•
KG
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
Discover more resources for Other
12 questions
IREAD Week 4 - Review
Quiz
•
3rd Grade - University
7 questions
Fragments, Run-ons, and Complete Sentences
Interactive video
•
4th Grade - University
7 questions
Renewable and Nonrenewable Resources
Interactive video
•
4th Grade - University
10 questions
DNA Structure and Replication: Crash Course Biology
Interactive video
•
11th Grade - University
5 questions
Inherited and Acquired Traits of Animals
Interactive video
•
4th Grade - University
5 questions
Examining Theme
Interactive video
•
4th Grade - University
20 questions
Implicit vs. Explicit
Quiz
•
6th Grade - University
7 questions
Comparing Fractions
Interactive video
•
1st Grade - University