C Programming Questions and Answers – Line Input & Output – 2

«
»

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Line Input & Output – 2”.

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

advertisement

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
View Answer

Answer: b
Explanation: None.

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

advertisement
advertisement
   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
View Answer

Answer: d
Explanation: None.
Participate in C Programming Certification Contest of the Month Now!
advertisement

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

  1.     #include <stdio.h>
  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
View Answer

Answer: d
Explanation: None.
advertisement

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

Answer: c
Explanation: None.
advertisement

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);
View Answer

Answer: b
Explanation: 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
View Answer

Answer: c
Explanation: None.

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

Answer: a
Explanation: 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
View Answer

Answer: c
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.

advertisement
advertisement

Leave a Comment

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.