C Questions and Answers – scanf – 2

«
»

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

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

advertisement

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
View Answer

Answer: b
Explanation: 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()?

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

a) 1
b) 2
c) 3
d) No return value
View Answer

Answer: c
Explanation: When the scanf() function completes reading all the data values, it returns number of values that are successfully read.
Participate in C Programming Certification Contest of the Month Now!
advertisement

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
View Answer

Answer: a
Explanation: scanf() returns the number of values that are successfully read. In the above statement, only integer value is read successfully.
advertisement

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
View Answer

Answer: b
Explanation: Using an incorrect specifier for the datatype being read will generate a run-time error.
advertisement

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);
View Answer

Answer: a
Explanation: 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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: c
Explanation: 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
View Answer

Answer: c
Explanation: 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?

scanf("%7s",ch);

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
View Answer

Answer: b
Explanation: 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?

scanf("%[^\n]s", ch);

a) read all character except new line
b) read all characters
c) read only new line character
d) syntax error
View Answer

Answer: a
Explanation: The symbol ^ when used before a escape sequence, does not read from the console.

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.

advertisement
advertisement

Leave a Comment

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 & technical discussions at Telegram SanfoundryClasses.