Formatted Input and Output in C

Quiz
•
Other
•
University
•
Hard
Harvinder Kaur
Used 9+ times
FREE Resource
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.
Create a free account and access millions of resources
Similar Resources on Wayground
9 questions
Estimating Sample Size

Quiz
•
University
10 questions
Services marketing - Quiz - Chapter 2 - Part 1 - 2024

Quiz
•
University
14 questions
Research Methods

Quiz
•
12th Grade - University
10 questions
SEEU2123 Quiz 1

Quiz
•
University
15 questions
Run with Aptitude

Quiz
•
University
12 questions
Chapter 1

Quiz
•
University
14 questions
Week 3 Homework Review

Quiz
•
University
10 questions
QUIZ #2 - NSTP 2

Quiz
•
University
Popular Resources on Wayground
15 questions
Hersheys' Travels Quiz (AM)

Quiz
•
6th - 8th Grade
20 questions
PBIS-HGMS

Quiz
•
6th - 8th Grade
30 questions
Lufkin Road Middle School Student Handbook & Policies Assessment

Quiz
•
7th Grade
20 questions
Multiplication Facts

Quiz
•
3rd Grade
17 questions
MIXED Factoring Review

Quiz
•
KG - University
10 questions
Laws of Exponents

Quiz
•
9th Grade
10 questions
Characterization

Quiz
•
3rd - 7th Grade
10 questions
Multiply Fractions

Quiz
•
6th Grade