This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Formatted Input – 2”.
Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.
1. Which of the following doesn’t require an & for the input in scanf()?
a) char name[10];
b) int name[10];
c) float name[10];
d) all of the mentioned
View Answer
Explanation: None.
2. Which of the following is an invalid method for input?
a) scanf(“%d%d%d”,&a, &b, &c);
b) scanf(“%d %d %d”, &a, &b, &c);
c) scanf(“Three values are %d %d %d”,&a,&b,&c);
d) none of the mentioned
View Answer
Explanation: None.
3. Which of the following represents the function for scanf()?
a) void scanf(char *format, …)
b) int scanf(char *format, …)
c) char scanf(int format, …)
d) char *scanf(char *format, …)
View Answer
Explanation: None.
4. What does scanf() function return?
a) Number of successfully matched and assigned input items
b) Nothing
c) Number of characters properly printed
d) Error
View Answer
Explanation: None.
5. What will be the output of the following C code?
#include <stdio.h>
void main()
{
int n;
scanf("%d", n);
printf("%d", n);
}
a) Prints the number that was entered
b) Segmentation fault
c) Nothing
d) Varies
View Answer
Explanation: scanf() expects a pointer/address to be passed. In the given code, we are simply passing a value which is uninitialized. This results in segmentation fault.
6. What will be the output of the following C statement?
int sscanf(char *string, char *format, arg1, arg2, …)
a) Scans the string according to the format in format and stores the resulting values through arg1, arg2, etc
b) The arguments arg1,arg2 etc must be pointers
c) Scans the string according to the format in format and stores the resulting values through arg1, arg2, etc, those arguments arg1,arg2 etc must be pointers
d) None of the mentioned
View Answer
Explanation: None.
7. The conversion characters d, i, o, u, and x may be preceded by h in scanf() to indicate?
a) A pointer to short
b) A pointer to long
c) Nothing
d) Error
View Answer
Explanation: None.
8. What will be the output of the following C code (when 4 and 5 are entered)?
#include <stdio.h>
void main()
{
int m, n;
printf("enter a number");
scanf("%d", &n);
scanf("%d", &m);
printf("%d\t%d\n", n, m);
}
a) Error
b) 4 junkvalue
c) Junkvalue 5
d) 4 5
View Answer
Explanation: None.
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.
- Apply for Computer Science Internship
- Check C Books
- Practice Computer Science MCQs
- Practice BCA MCQs
- Apply for C Internship