TCS C MCQ on File Handling

1. The value of EOF is_____
a) -1 
b) 0
c) 1
d) 10

2. Which of the following true about FILE *fp
a) FILE is a keyword in C for representing files and fp is a variable of FILE type.
b) FILE is a structure and fp is a pointer to the structure of FILE type
c) FILE is a stream
d) FILE is a buffered stream

 Explanation: fp is a pointer of FILE type and FILE is a structure that store following information about opened file.

3. The first and second arguments of fopen are ______
a) A character string containing the name of the file & the second argument is the mode
b) A character string containing the name of the user & the second argument is the mode
c) A character string containing file poniter & the second argument is the mode
d) None of the mentioned

4. If there is any error while opening a file, fopen will return
a) Nothing
b) EOF
c) NULL 
d) Depends on compiler

5. fseek() should be preferred over rewind() mainly because
a) rewind() doesn’t work for empty files
b) rewind() may fail for large files
c) In rewind, there is no way to check if the operations completed successfully 
d) All of the above

6. FILE is of type ______
a) int type
b) char * type
c) struct type 
d) None of the mentioned

7. FILE reserved word is
a) A structure tag declared in stdio.h
b) One of the basic datatypes in c
c) Pointer to the structure defined in stdio.h
d) It is a type name defined in stdio.h

8. getc() returns EOF when
a) End of files is reached
b) When getc() fails to read a character
c) Both of the above —
d) None of the above

9. Which of the following functions from “stdio.h” can be used in place of printf()?
a) fputs() with FILE stream as stdout.
b) fprintf() with FILE stream as stdout. 
c) fwrite() with FILE stream as stdout.
d) All of the above three – a, b and c.
e) In “stdio.h”, there’s no other equivalent function of printf()

10. fputs adds newline character
a) True
b) False
c) Depends on the standard
d) Undefined behaviour

11. puts function adds newline character
a) True 
b) False
c) Depends on the standard
d) Undefined behaviour

One comment on “TCS C MCQ on File Handling”