Prerequisite : File handling
1. What is the output of this program by manipulating the text file?
Options:
a) Error
b) Success
c) Runtime Error
d) Can’t say
Answer : d
Explanation : If myfile.txt exists, then it will delete the file. Else it will print an error message.
2. What is the output of this program?
Options:
a) Count of ‘$’ symbol
b) Error opening file
c) Any of the mentioned
d) None of the mentioned
Answer : c
Explanation : Any one is possible – Either the file doesn’t exist or If exist, it will print the total number of ‘$’ character.
3. What is the output of this program in the text file?
Options:
a) ABCD
b) ABC
c) ABCDE
d) None of the mentioned
Answer : c
Explanation : In this program, We are printing from A to E by using the putc function.
Output:
$ g++ out2.cpp
$ a.out
ABCDE
4. What is the name of the myfile2 file after executing this program?
Options:
a) name
b) new
c) newname
d) None of the mentioned
Answer : c
Explanation : In this program, We are renaming the myfile2 to newname by using the function rename.
Output:
myfile2.txt is renamed to newname.txt
5. How many number of characters are available in newname.txt?
Options:
a) 10
b) 15
c) Depends on the text file
d) None of the mentioned
Answer : c
Explanation : In this program, We are reading the number of characters in the program by using the function feof.
Output:
$ g++ out4.cpp
$ a.out
162
Related Article : Quiz on File Handling