250+ TOP MCQs on Ungetc and Answers

C programming Objective Questions on “Ungetc Function”. One shall practice these Objective Questions to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C programming Objective Questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C programming Objective Questions on “Ungetc Function” along with answers, explanations and/or solutions:

1. ungetc() can be used only with getc().
a) true
b) false
c) depends on the standard
d) depends on the platform
Answer: b
Clarification: None.

2. Which character of pushback is guaranteed per file?
a) True
b) False
c) Depends on the compiler
d) Depends on the platform
Answer: a
Clarification: None.

3. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int n;
  5.         scanf("%d", &n);
  6.         ungetc(n, stdin);
  7.         scanf("%d", &n);
  8.         printf("%dn", n);
  9.         return 0;
  10.     }

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
Answer: b
Clarification: None.

4. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         char n[20];
  5.         fgets(n, 19, stdin);
  6.         ungetc(n[0], stdin);
  7.         scanf("%s", n);
  8.         printf("%sn", n);
  9.         return 0;
  10.     }

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
Answer: d
Clarification: None.

5. What will be the output of the following C code considering user typed jkl?

  1.     #include 
  2.     int main()
  3.     {
  4.         char n[20];
  5.         fgets(n, 19, stdin);
  6.         ungetc(n[0], stdin);
  7.         printf("%sn", n);
  8.         return 0;
  9.     }

a) jkl
b) kl
c) Undefined behaviour
d) jk
Answer: a
Clarification: 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
Answer: a
Clarification: 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);
Answer: b
Clarification: 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
Answer: c
Clarification: None.

  250+ TOP MCQs on If-then-else Statements and Answers

Leave a Comment

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

Scroll to Top