Computer StudyMCQ Computer ScienceQuiz Computer ScienceUGC NET

C Programming Questions and Answers – Ungetc

C Programming Questions and Answers – Ungetc

 

1.ungetc can be used only with getc.

a) true

b) false

c) Depends on the standard

d) Depends on the platform

View Answer

Answer:b

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

Answer:a 

3.What is the output of this 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

Answer:b

4.What is the output of this 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

Answer:d 

5.What is the output of this 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

Answer:a

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

Answer:a 

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

Answer:b 

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

Answer:c  

9.Which of the following the is the correct declaration for ungetc?

a) int ungetc(int c, FILE fp);

b) int ungetc(int *c, FILE fp);

c) int ungetc(int c, FILE *fp);

d) int ungetc(int *c, FILE *fp);

View Answer

Answer:c 

10.Which of the following cannot be used with ungetc?

a) scanf

b) getc

c) getchar

d) printf

View Answer

Answer:d

11.What does the ungetc function return for the following expression?

ungetc(c, fp);//where declarations are int c and FILE *fp

a) It returns character c

b) It returns EOF for an error

c) Both a and b

d) Either a or b

View Answer

Answer:d 

12.int ungetc(int c, FILE *fp) returns

a) Either c or EOF for an error

b) Nothing

c) fp

d) None of the mentioned

View Answer

Answer:a 

13.Only _____character of pushback is guaranteed per file when ungetc is used.

a) Two

b) One

c) Many

d) Zero

View Answer

Answer:b

14.ungetc may be used with

a) scanf

b) getc

c) getchar

d) All of the mentioned

View Answer

Answer:d 

15.The syntax for ungetc is

a) void ungetc(int c, FILE *fp)

b) int ungetc(int c, FILE *fp)

c) int ungetc(String c, FILE *fp)

d) int getc(int c, FILE *fp)

View Answer

Answer:b 

Related Articles

Leave a Reply

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

Back to top button