Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Language%20in%20C%20Interview%20Questions%20and%20Answers

Question: When we open a file, how does functions like fread( )/fwrite( ), etc. get to know from where to read or to write the data?

Answer: When we open a file for read/write operation using function like fopen( ), it returns a pointer to the structure of type FILE. This structure stores the file pointer called position pointer, which keeps track of current location within the file. On opening file for read/write operation, the file pointer is set to the start of the file. Each time we read/write a character, the position pointer advances one character. If we read one line of text at a step from the file, then file pointer advances to the start of the next line. If the file is opened in append mode, the file pointer is placed at the very end of the file. Using fseek( ) function we can set the file pointer to some other place within the file.
Is it helpful? Yes No

Most helpful rated by users:

©2024 WithoutBook