I want to know the difference between a file descriptor and file pointer.
Also, in what scenario would you use one instead of the other?
cfile-descriptorfile-pointer
I want to know the difference between a file descriptor and file pointer.
Also, in what scenario would you use one instead of the other?
Best Answer
A file descriptor is a low-level integer "handle" used to identify an opened file (or socket, or whatever) at the kernel level, in Linux and other Unix-like systems.
You pass "naked" file descriptors to actual Unix calls, such as
read()
,write()
and so on.A
FILE
pointer is a C standard library-level construct, used to represent a file. TheFILE
wraps the file descriptor, and adds buffering and other features to make I/O easier.You pass
FILE
pointers to standard C functions such asfread()
andfwrite()
.