Unit II · Viva Questions
Revise the concepts orally; open a study answer when you need more detail.
Explain files, FILE pointers, opening modes and closing.
- Does fclose remove the stored file?
- No.
- Which mode would unexpectedly erase an existing file’s contents?
- w, and similarly w+ when opening succeeds.
Explain character, formatted and line-based text file input/output.
- Why store fgetc in int rather than char?
- To preserve the distinction needed for EOF.
- Does fputs automatically add a newline?
- No.
Compare text and binary file processing.
- Does saving a pointer save the linked objects?
- No.
- Is a native fwrite structure file universally portable?
- No. Layout and representation can differ.
Explain fread and fwrite with a binary-file example.
- What should a short fread result trigger?
- Handle only completed elements and determine whether end or an error caused the short result.
- Which modes are used here?
- wb for writing and rb for reading.
Explain searching a file-based record database by key.
- Must sequential record search use sorted keys?
- No.
- Can a read error safely be reported as ordinary Not found?
- No. It should be distinguished from a completed unsuccessful search.
Explain feof, ferror and clearerr and correct end-of-file testing.
- Is EOF a data byte stored at every file’s end?
- No.
- Does clearerr repair a failed disk?
- No. It only clears stream indicators.
Explain file positioning with fseek, ftell, rewind, fgetpos and fsetpos.
- Which origin refers to the file beginning?
- SEEK_SET.
- Is a text ftell result always an ordinary byte count?
- No.
Explain argc and argv with a checked numeric-argument example.
- Are argv entries already integer values?
- No. They are strings.
- Why check the end pointer after strtol?
- To detect missing digits or leftover characters.
Explain multifile programming, headers, declarations and linking.
- Does including a header link the missing function definition?
- No.
- Where should a normal shared function have its external definition?
- In one appropriate source file.
Explain append and update streams and safe transitions between reading and writing.
- Does fseek let append-mode writes overwrite the middle?
- Append-mode writes still go to the end.
- What transition is normally needed after input before output?
- A suitable file-positioning operation, except for the specified end-of-file case.