This set of C Multiple Choice Questions & Answers (MCQs) focuses on “File Operations – 2”.
Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.
1. what is the function of fputs()?
a) read a line from a file
b) read a character from a file
c) write a character to a file
d) write a line to a file
View Answer
Explanation: The fputs() is used to write a line to a file. fputs() syntax can be written as
int fputs(const char *str, FILE *stream);
2. What does the following C code snippet mean?
char *gets(char *s)
a) reads the next input line into the array s
b) writes the line into the array s
c) reads the next input character into the array s
d) write a character into the array
View Answer
Explanation: gets() reads the next input line into the array s, terminating newline is replaced with ‘\0’.It returns s, or NULL if end of file or error occurs.
3. Which function will return the current file position for stream?
a) fgetpos()
b) fseek()
c) ftell()
d) fsetpos()
View Answer
Explanation: The current file position is returned by ftell() function for stream, or -1L on error.
4. Select the right explanation for the following C code snippet.
int fgetpos(FILE *stream, fpos_t *s)
a) records the current position in stream in *s
b) sets the file position for stream in *s
c) positions stream at the position recorded in *s
d) reads from stream into the array ptr
View Answer
Explanation:fgetpos() records the current position in stream in *s, for subsequent use by fsetpos() . The type fpost_t is suitable for recording such values.
5. Which functions is declared in <errno. h>?
a) fseek()
b) ftell()
c) ferror()
d) fsetpos()
View Answer
Explanation: ferror() is declared under <errno. h>. ferror() returns non-zero if the error indicator for stream is set.
6. setvbuf() and setbuf() function controls buffering for the stream.
a) true
b) false
View Answer
Explanation: setvbuf() and setbuf() controls buffering for the stream. If buff is NULL, buffering is turned off for the stream.
7. The functions vprintf(), vfprintf(), and vsprintf() are not equivalent to the corresponding printf() functions except the variable argument list.
a) true
b) false
View Answer
Explanation: The functions vprintf() , vfprintf() , and vsprintf() are similar to the corresponding printf() functions except that the variable argument list is replaced by arg.
8. The______function reads atmost one less than the number of characters specified by size from the given stream and it is stored in the string str.
a) fget()
b) fgets()
c) fput()
d) fputs()
View Answer
Explanation: The fgets() function reads one less than the number of characters indicated by the size from the given stream and it is stored in the string str. The fgets() terminates as soon as it encounters either a newline character, EOF, or other error.
9. What does the following C code snippet mean?
int ungetc(int c, FILE *stream)
a) pushes c back onto a stream
b) deletes c from the stream
c) reads frequency of c in stream
d) no action is taken by the command
View Answer
Explanation: ungetc() pushes c back onto stream, where it will be returned on the next read. Only one character of pushback per stream is Guaranteed.
10. Choose the correct difference between getc() and fgetc().
a) If it is not a macro, it may evaluate stream more than once
b) if it is amacro, it may not evaluate stream more than once
c) if it is a macro, it may evaluate stream more than once
d) no difference between fgetc() and getc()
View Answer
Explanation: getc() is equivalent to fgetc() except that if it is a macro, it may evaluate more than once.
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.
If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]
- Practice BCA MCQs
- Apply for C Internship
- Apply for Computer Science Internship
- Watch Advanced C Programming Videos
- Check Computer Science Books