This section includes 7 InterviewSolutions, each offering curated multiple-choice questions to sharpen your Current Affairs knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
What is the closing of the file? |
|
Answer» Closing Files: During a write to a file, the data written is not put on the disk immediately. It is stored in a buffer. When the buffer is full, all its contents are actually written to the disk. The process of emptying the buffer by writing its contents to disk is called flushing the buffer. Losing the file flushes the buffer and releases the space taken by the FILE structure which is returned by fopen. For this fclose () function is used. Syntax: fclose (File * stream (s); |
|
| 2. |
The last location of a file is:(a) EOF(b) END(c) LAST(d) CLOSE |
|
Answer» Correct option is (a) EOF |
|
| 3. |
Describe the main features of printf and getchar function. |
|
Answer» printf ( ) → This function writes formatted data to screen. This function allows to supply the input in a fixed format and to obtain the output in the specified form. The printf () function interprets the contents of the format string. Syntax: Printf (“formatted string”, variables); if needed getchar ( ): Using this function any single ASCII character can be inputted in any char type of a variable. This function is available in stdio.h header file so it must be included in the program, in the beginning, using # include declarative. #include<stdio.h> |
|
| 4. |
In which type of file, accessing a particular record is faster? |
|
Answer» Random data file |
|
| 5. |
What do you know about ffiush() statement? |
|
Answer» If the given stream has buffered output, fflush writes the output for a stream to the associated file. |
|
| 6. |
Which statement is used to close a file? |
|
Answer» fclose() statement |
|
| 7. |
Which file pointer position of seeking function seeks from the beginning? |
|
Answer» SEEK SET file pointer position of seeking function seeks from the beginning. |
|
| 8. |
Which statement is used to read the data from a file? |
|
Answer» fread() statement is used to read the data from a file. |
|
| 9. |
When data is to be written on a file, in which mode it should be opened? |
|
Answer» ‘w’ mode (for writing) |
|
| 10. |
Explain fread () and fwrite () functions. |
|
Answer» fread( ): This function reads a specified number of equalsized data items from an input stream into a block, fread returns the number of items (not bytes) actually read on success. Syntax: fread (& name_of_structure, size_of_(structure name), l, file pointer); e.g., struct employee Here, the fread function can read 22 bytes of information from the file pointed by file pointer fp. fwrite( ): This function appends a specified number of equal-sized data items to an output file. Syntax: fwrite (& struct—name, size of (struct), 1, fp); e.g., street address |
|
| 11. |
Write about different modes in which a file can be opened. |
|
Answer» File Opening Modes: The tasks performed by fopen() when a file is opened in each of these modes are also mentioned. Character Used for Mode → Meaning w → Create for write r → Open for reading a → Open for append/create a new file w+ → Create for read/write r+ → Open for read/write a+ → Open for read/write/create new file |
|
| 12. |
WAP to copy the contents of one file to another? |
|
Answer» Program: #include<stdio.h> |
|
| 13. |
Which function sets the file pointer associated with a stream to a new position:(a) fseek ()(b) perror(c) rename(d) rewind |
|
Answer» Correct option is (a) fseek () |
|
| 14. |
Which function is used to read a line from file:(a) gets ()(b) fgets ()(c) readline ()(d) gets () |
|
Answer» Correct option is (b) fgets () |
|
| 15. |
Which function is used to close a file?(a) CLOSE(b) END(c) EOF(d) None of these |
|
Answer» Correct option is (b) END |
|
| 16. |
What is reading files? |
|
Answer» Reading from files: To read from a file, ‘C’ provides the following functions: To read data from file, it should exist. fscanf (): This function is used to read data from a file. It is very similar to scanf () function. It scans a series of input fields (one at a time). Syntax: fscanf () file * stream, “format specifiers” , “Variables”). |
|