250+ TOP MCQs on scanf and Answers

C Multiple Choice Questions & Answers on “scanf – 2”.

1. Select the correct value of i from given options i=scanf(“%d %d”, &a, &b);
a) 1
b) 2
c) 3
d) No value assigned
Answer: b
Clarification: i stores the number of read data from the stream. It is useful for detecting an error in data input.

2. If the user enters 1 3.2 s, what value will be returned by the scanf()?

scanf("%d %f %c", &s1, &s2, &s3);

a) 1
b) 2
c) 3
d) No return value
Answer: c
Clarification: When the scanf() function completes reading all the data values, it returns number of values that are successfully read.

3. If the user enters 1 s 3.2, what value will be returned by the scanf()?

scanf("%d %f %c", &a, &b, &c);

a) 1
b) 2
c) 3
d) no return value
Answer: a
Clarification: scanf() returns the number of values that are successfully read. In the above statement, only integer value is read successfully.

4. What error will be generated on using incorrect specifier for the datatype being read?
a) compile error
b) run-time error
c) logical error
d) no error
Answer: b
Clarification: Using an incorrect specifier for the datatype being read will generate a run-time error.

5. What is the prototype of scanf function?
a) scanf(“controlstring”,arg1,arg2,arg3,….,argn);
b) scanf(“control string”, variable list);
c) scanf(” varible list,”, control string);
d) scanf(“arg1,arg2,arg3,….,argn”, control string);
Answer: a
Clarification: The syntax of the scanf() can be given as,scanf(“control string”, arg1,arg2,arg3,….,argn);

6. Control string specifies the type and format of the data that has to be obtained from the keyboard.
a) true
b) false
Answer: a
Clarification: The control string specifies the type and format of the data that has to be obtained from the keyboard and store in the memory locations pointed by the arguments arg1,arg2….argn.

7. What is the qualifying input for the type specifier G?
a) floating point numbers
b) floating point numbers in exponential format
c) floating point numbers in the shorter of exponential format
d) not a type specifier
Answer: c
Clarification: G is a type specifier used to take an input of floating point numbers in the shorter of exponential format.

8. scanf() is a predefined function in______header file.
a) stdlib. h
b) ctype. h
c) stdio. h
d) stdarg. h
Answer: c
Clarification: scanf() is a predefined function in “stdio.h” header file.printf and scanf() carry out input and output functions in C. These functions statements are present in the header file stdio.h.

9. What does the C statement given below says?

a) read string with minimum 7 characters.
b) read string with maximum 7 characters
c) read string exactly to 7 characters
d) read string with any number of characters
Answer: b
Clarification: In the above statement the control string specifies the size of string to be 7(i.e only 7 characters can be entered in a string).

10. What is the meaning of the following C statement?

a) read all character except new line
b) read all characters
c) read only new line character
d) syntax error
Answer: a
Clarification: The symbol ^ when used before a escape sequence, does not read from the console.

Leave a Reply

Your email address will not be published. Required fields are marked *