C Questions and Answers – printf – 1

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “printf – 1”.

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

1. The syntax of printf() function is printf(“control string”, variable list) ;what is the prototype of the control string?
a) %[flags][.precision][width][length]specifier
b) %[flags][length][width][.precision]specifier
c) %[flags][width][.precision][length]specifier
d) %[flags][.precision][length][width]specifier
view Answer

Answer: c
Explanation: The prototype of control string is %[flags][width][.precision][length]specifier. Each control string must begin with % sign.

2. The parameter control string in the printf () is a C String that contains text to be __________
a) taken from a standard output device
b) written on to the standard output device
c) received from the standard output device
d) nothing can be said
view Answer

Answer: b
Explanation: After the control string, the function can have many additional arguments as specified in the control string, this parameter contains the text to be written on to the standard output device.
advertisement
advertisement

3. Output justification such as decimal point, numerical sign, trailing zeros or octal are specified.
a) specifier
b) flags
c) precision
d) decimal
view Answer

Answer: b
Explanation: Flags specify output justification such as Left-justify within the data given field width, Displays the data with its numeric sign, used to provide additional specifiers like o, x, X for octal, left padding of a number.

4. What symbol is used to Left-justify within the data given field width?
a) -(minus sign)
b) +(plus sign)
c) #
d) 0
view Answer

Answer: a
Explanation: To left-justify the data use minus sign(-) in the flags field.
Note: Join free Sanfoundry classes at Telegram or Youtube

5. What specifies the minimum number of characters to print after being padded with zeros or blank spaces?
a) flags
b) length
c) width
d) precision
view Answer

Answer: c
Explanation: width specifies the minimum number of positions in the output.

6. The maximum number of characters to be printed is specified by __________
a) precision
b) width
c) length
d) flags
view Answer

Answer: a
Explanation: Precision specifies the maximum number of characters to print.
advertisement

7. ________is used to define the type and the interpretation of the value of the corresponding argument.
a) precision
b) specifiers
c) flags
d) decimal
view Answer

Answer: b
Explanation: Specifiers is used to define the type and the interpretation of the value of the corresponding argument. Example: c for a single character, d for decimal values etc.

8. A conversion specification %7.4f means ____________
a) print a floating point value of maximum 7 digits where 4 digits are allotted for the digits after the decimal point
b) print a floating point value of maximum 4 digits where 7digits are allotted for the digits after the decimal point
c) print a floating point value of maximum 7 digits
d) print a floating point value of minimum 7 digits where 4 digits are allotted for the digits after the decimal point
view Answer

Answer: a
Explanation: The conversion specification %7.4f means that it will print floating point number maximum of 7 digits and 4 digits after the decimal point.
advertisement

9. Choose the correct description for control string %-+7.2f.
a) – means display the sign, + means left justify, 7 specifies the width and 2 specifies the precision
b) – means left justify, + means display the sign, 7 specifies the width and 2 specifies the precision
c) – means display the sign, + means left justify, 7 specifies the precision and 2 specifies the width
d) – means left justify, + means display the sign, 7 specifies the precision and 2 specifies the width
view Answer

Answer: b
Explanation: The given control string %-+7.2f means that – is for left justify, + to display sign, 7 specifies the precision and 2 specifies the width.

10. What error is generated on placing an address operator with a variable in the printf statement?
a) compile error
b) run-time error
c) logical error
d) no error
view Answer

Answer: b
Explanation: Placing an address operator with a variable in the printf statement will generate a run-time error.

Sanfoundry Global Education & Learning Series – C Programming Language.

To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.