+ 1

Where are contents of file pointers stored in C/C++

So this is how we read files in C/C++ https://code.sololearn.com/c3MSc8YymEed/?ref=app But my question is, where the file pointer '*f' is pointing towards. Is the file stored in the RAM of the system and pointing towards that or is pointing towards the storage where file is stored ? I have seen enough of this answers everywhere (not needed) " A file pointer is a pointer to a structure, which contains information about the file, including its name, current position of the file, whether the file is being read or written, and whether errors or end of the file have occurred. The user does not need to Know the details, because the definitions obtained from stdio.h include a structure declaration called FILE. The only declaration needed for a file pointer is symbolized by FILE *fp; Now we use this file pointer fp to perform operations. " I am currently working on embedded projects where RAM and Storages matter , so I need to find where the contents of file pointers are stored, RAM or storage device?

12th Jun 2022, 6:55 AM
CoderBittu
CoderBittu - avatar
2 Answers
+ 5
The file you are working on stays where it was. The FILE* is only a file "descriptor", i.e., it only holds information about the file, it does not point to the file itself. fopen() makes system calls to interact with the filesystem, and in the end either returns the FILE* pointer with all the required data about the file. The answers on this thread explain pretty well what happens when you open a file: https://stackoverflow.com/questions/33495283/what-does-opening-a-file-actually-do
12th Jun 2022, 7:43 AM
XXX
XXX - avatar
+ 4
Jay Matthews With all due respect, "try using a search engine" does not apply to this question. It's a fairly specific question. Yes, the OP could've found the thread I linked in my answer, but they were going on some initial assumptions that made it more difficult for them to search for an answer. I usually ignore answers like yours in case I disagree with them, but I've seen a rise in them lately. I know you are a respected member here and you know what you're doing, but I've seen many less experienced community members give answers like "use a search engine" when the question is not deserving of it (emphasis on this phrase). I feel like if the OP is asking genuinely and is not expecting to be spoonfed, we should atleast suggest them some search terms so that they can get better at searching, instead of just asking them to use a search engine.
12th Jun 2022, 7:53 AM
XXX
XXX - avatar