C Questions and Answers – printf – 1

«
»

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

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.
advertisement

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.

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.
advertisement
advertisement

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.

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.
advertisement

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.

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.
advertisement

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.

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.
advertisement

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.

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!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter