This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Ungetc – 1”.
Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.
1. ungetc() can be used only with getc().
a) true
b) false
c) depends on the standard
d) depends on the platform
View Answer
Explanation: None.
2. Which character of pushback is guaranteed per file?
a) True
b) False
c) Depends on the compiler
d) Depends on the platform
View Answer
Explanation: None.
3. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
ungetc(n, stdin);
scanf("%d", &n);
printf("%d\n", n);
return 0;
}
a) Compile time error
b) Whatever is typed by the user first time
c) Whatever is typed by the user second time
d) Undefined behaviour
View Answer
Explanation: None.
4. What will be the output of the following C code?
#include <stdio.h>
int main()
{
char n[20];
fgets(n, 19, stdin);
ungetc(n[0], stdin);
scanf("%s", n);
printf("%s\n", n);
return 0;
}
a) Compile time error
b) Whatever string user types second time
c) Whatever string user types first time
d) First character of whatever user types first time and whatever user types second time
View Answer
Explanation: None.
5. What will be the output of the following C code considering user typed jkl?
#include <stdio.h>
int main()
{
char n[20];
fgets(n, 19, stdin);
ungetc(n[0], stdin);
printf("%s\n", n);
return 0;
}
a) jkl
b) kl
c) Undefined behaviour
d) jk
View Answer
Explanation: None.
6. How many characters for pushback is guaranteed per file while using ungetc(c, fp);?
a) Only 1 character
b) Characters within 1 word
c) Characters within 1st new-line
d) All characters upto NULL character
View Answer
Explanation: None.
7. Which of the following is the correct syntax for calling function ungetc?
Assume int c and FILE *fp
a) ungetc(c,*fp);
b) ungetc(c, fp);
c) ungetc(fp, c);
d) ungetc(*fp,c);
View Answer
Explanation: None.
8. ungetc() is used __________
a) to get a char
b) to get an int
c) to push a character back to file
d) nothing
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 Computer Science Books
- Apply for C Internship
- Watch Advanced C Programming Videos
- Practice Computer Science MCQs