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?
-
#include
-
int X(char *s, FILE *iop)
-
{
-
int c;
-
while (c = *s++)
-
putc(c, iop);
-
return ferror(iop) ? EOF : 0;
-
}
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.