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.
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.

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!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter

Check his free tutorial videos on Advanced C Programming. Join his Sanfoundry-Classes telegram channel for all videos and queries on Programming, Data-Structures, Kernel, Personality development and Mentoring.