This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Formatted Input – 1”.
Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.
1. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int n;
scanf("%d", n);
printf("%d\n", n);
return 0;
}
a) Compilation error
b) Undefined behavior
c) Whatever user types
d) Depends on the standard
View Answer
Explanation: None.
2. What will be the output of the following C code?
#include <stdio.h>
int main()
{
char *n;
scanf("%s", n);
return 0;
}
a) Compilation error
b) Undefined behavior
c) Nothing
d) None of the mentioned
View Answer
Explanation: None.
3. What will be the output of the following C code?
#include <stdio.h>
int main()
{
char n[] = "hello\nworld!";
char s[13];
sscanf(n, "%s", s);
printf("%s\n", s);
return 0;
}
a) hellonworld!
b)
hello world!
c) hello
d) hello world!
View Answer
Explanation: The array n contains a string which has a newline character in between the strings “hello” and “world”. A newline character is considered as a whitespace character for inputs for the scanf(), sscanf() and fscanf() functions. So, the sscanf() function will only copy upto the string “hello” into the array s. Hence, the output of the printf() function be only the string “hello”.
4. What will be the output of the following C code?
#include <stdio.h>
int main()
{
short int i;
scanf("%hd", &i);
printf("%hd", i);
return 0;
}
a) Compilation error
b) Undefined behavior
c) Whatever user types
d) None of the mentioned
View Answer
Explanation: None.
5. What will be the output of the following C code?
#include <stdio.h>
int main()
{
short int i;
scanf("%*d", &i);
printf("%hd", i);
return 0;
}
a) Compilation error
b) Somegarbage value
c) Whatever user types
d) Depends on the standard
View Answer
Explanation: None.
6. What will be the output of the following C code?
#include <stdio.h>
int main()
{
short int i;
scanf("%*hd", &i);
printf("%hd", i);
return 0;
}
a) Compilation error
b) Somegarbage value
c) Whatever user types
d) Depends on the standard
View Answer
Explanation: None.
7. What will be the output of the following C code?
#include <stdio.h>
int main()
{
short int i;
scanf("%h*d", &i);
printf("%hd", i);
return 0;
}
a) Compilation error
b) Undefined behavior
c) Somegarbage value
d) Depends on the standard.
View Answer
Explanation: None.
8. Which of the following is NOT a delimiter for an input in scanf?
a) Enter
b) Space
c) Tab
d) None of the mentioned
View Answer
Explanation: None.
9. If the conversion characters of int d, i, o, u and x are preceded by h, it indicates?
a) A pointer to int
b) A pointer to short
c) A pointer to long
d) A pointer to char
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.
- Check Computer Science Books
- Watch Advanced C Programming Videos
- Apply for C Internship
- Check C Books
- Practice BCA MCQs