This set of C Multiple Choice Questions & Answers (MCQs) focuses on “scanf – 1”.
Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.
1. The syntax of the scanf() is scanf(“control string “, arg1,arg2,arg3,….,argn); the prototype of control string is ____________
a) [=%[width][modifiers]type=]
b) [=%[modifiers][width]type=]
c) [=%[width] [modifiers]]
d) [width][modifiers]
View Answer
Explanation: scanf() starts with the symbol % followed by the width, modifier, type of the argument.
2. What is the use of symbol * in the control string as shown [=%[*][width] [modifiers] type=]?
a) * is optional and used when the data should be read from the stream but ignored
b) * is not optional, used to read data from the stream but it is not ignored
c) * is not optional, it is used to read data stream but ignored
d) * is optional and used to read data from stream but it is not ignored
View Answer
Explanation: * is an optional argument, it indicates that data should be read from the steam but ignored (not stored in a memory location)
3. What action is carried out by scanf if a user enters any blank spaces, tabs, and newlines?
a) consider as input
b) ignores it
c) produces error
d) nothing can be said
View Answer
Explanation: The scanf() function ignores any blank spaces, tabs, and newlines entered by the user. This scanf() function just returns the number of input fields successfully scanned and stored.
4. What error will generate if the read and write parameters are not separated by commas?
a) run-time error
b) compile error
c) logical error
d) no error
View Answer
Explanation: A compile error will be generated if the read and write parameters are not separated by commas.
5. What will be the output of the following C code?
char str[] =”Good”; scanf(“%s”, str);
a) compile error
b) run-time error
c) good
d) logical error
View Answer
Explanation: String can be read from the stream without the use of address of operator (&).
6. What will be the output of the following C code?
scanf(“ %d %d %d”,&n1,&n2);
a) read data for two
b) generate error
c) read data for three
d) nothing can be said
View Answer
Explanation: The following scanf() statement will generate an error as no variable address is given for the third conversion specification.
7. What form the data must be entered for the given C code?
scanf(“%d / %d”, &n1,&n2);
a) 6 9
b) 6/9
c) compile error
d) run-time error
View Answer
Explanation: The slash in the control String are neither white space characters nor a part of conversion specification, so the user must enter data of the form 6/9.
8. A fatal error will be generated if the format string is ended with a white space character.
a) true
b) false
View Answer
Explanation: An error will be generated if the format string %s is ended with white space character.
9. Explain the format string "%5d%s %c"
a) five characters as a decimal integer, then reads the remaining as a string and then scans the first non-whitespace character
b) compile error
c) run-time error
d) read first five characters as a decimal and ignore the rest
View Answer
Explanation: The above format string reads the first five characters as a decimal integer, then reads the remaining as a string until a space, newline or tab is found, then reads the first non-whitespace character.
10. _____ is an optional argument that gives the maximum number of characters to be read.
a) modifiers
b) width
c) precision
d) length
View Answer
Explanation: Width is the argument that gives the maximum number of characters to be read. Few characters will be read if the scanf function encounters white space and it will stop processing further.
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.
- Check C Books
- Practice Computer Science MCQs
- Apply for Computer Science Internship
- Apply for C Internship
- Check Computer Science Books