C File Management-3
1. Which is data type of file pointer is _______
a) int
b) double
c) void
d) File
Answer: D
No explanation is given for this question.
2. When a C program is started, O.S environment is responsible for opening file and providing pointer for that file?
a) Standard input
b) Standard output
c) Standard error
d) All of the above
Answer: D
No explanation is given for this question.
3. If there is any error while opening a file, fopen will return?
a) Nothing
b) EOF
c) NULL
d) Depends on compiler
Answer: C
No explanation is given for this question.
4. It is not possible to combine two or more file opening mode in open () method.
a) TRUE
b) FALSE
Answer: B
No explanation is given for this question.
5. What is the return value of putchar()?
a) The character written
b) EOF if an error occurs
c) Nothing
d) Both character written & EOF if an error occurs
Answer: D
No explanation is given for this question.
6. What is the purpose of "rb" in fopen() function used below in the code?
FILE *fp; fp = fopen("demo.txt", "rb");
a) Open "demo.txt" in binary mode for reading
b) Create a new file "demo.txt" for reading and writing
c) Open "demo.txt" in binary mode for reading and writing
d) None of the above
Answer: A
The file demo.txt will be opened in the binary mode.
7. getc() returns EOF when
a) When getc() fail to read the character
b) When end of file is reached
c) Both A and B
d) None of the above
Answer: C
No explanation is given for this question.
8. If the mode includes b after the initial letter, what does it indicates?
a) text file
b) big text file
c) binary file
d) blueprint text
Answer: C
If the mode consists of letter b after the first letter as in, “rb” or “w+b”, it indicates binary file.
9. fflush(NULL) flushes all ____________
a) input streams
b) output streams
c) previous contents
d) appended text
Answer: B
fflush(FILE *stream) – fflush() causes any buffered but unwritten to be written on an Output stream. On an input stream, the effect is undefined. fflush(NULL) flushes all output streams.
10. _____removes the named file, so that a subsequent attempt to open it will fail.
a) remove(const *filename)
b) remove(filename)
c) remove()
d) fclose(filename)
Answer: A
remove(const *filename) removes the named file, so that a subsequent attempt to open it will fail. It returns non-zero of the attempt fails.