250+ TOP MCQs on Line Input & Output and Answers

tough C questions on “Line Input & Output”. One shall practice these 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 questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of tough C questions on “Line Input & Output” along with answers, explanations and/or solutions:

1. What is the size of array “line” used in fgets(line, maxline, *fp) function?
a) maxline – 1
b) maxline
c) maxline + 1
d) Size is dynamic
Answer: b
Clarification: None.

2. What will be the output of the following C function when EOF returns?

   int fputs(char *line, FILE *fp)

a) ‘�’ character of array line is encountered
b) ‘n’ character in array line is encountered
c) ‘t’ character in array line is encountered
d) When an error occurs
Answer: d
Clarification: None.

3. Identify X library function for line input and output in the following C code?

  1.     #include 
  2.     int X(char *s, FILE *iop)
  3.     {
  4.         int c;
  5.         while (c = *s++)
  6.         putc(c, iop);
  7.         return ferror(iop) ? EOF : 0;
  8.     }

a) getc
b) putc
c) fgets
d) fputs
Answer: d
Clarification: None.

4. Which function has a return type as char pointer?
a) getline
b) fputs
c) fgets
d) all of the mentioned
Answer: c
Clarification: None.

5. Which of the following is the right declaration for fgets() inside the library?
a) int *fgets(char *line, int maxline, FILE *fp);
b) char *fgets(char *line, int maxline, FILE *fp);
c) char *fgets(char *line, FILE *fp);
d) int *fgets(char *line, FILE *fp);
Answer: b
Clarification: None.

6. what is the return value of fputs()?
a) EOF if an error occurs
b) Non-negative if no error
c) EOF if an error occurs & Non-negative if no error
d) None of the mentioned
Answer: c
Clarification: None.

7. gets() and puts() operate on ___________
a) stdin and stdout
b) files
c) stderr
d) nothing
Answer: a
Clarification: None.

8. gets() does the following when it reads from stdin.
a) Deletes the ‘t’
b) Puts adds it.
c) Deletes the terminating ‘n’
d) Nothing
Answer: c
Clarification: None.

contest

Leave a Reply

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