Whats is difference between file descriptor and file pointer?

By -

After having 1 year of experience in c programming when someone has asked this to me i was surprised that why i dont know this…!!

Well when i will going to interview someone in someday this would be my 1st question to him/her…!!!

File Descriptor :  

  “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.”

 int fd;
 fd = open(path, O_CREAT | O_RDONLY, 0644);

This way you are using that is file-descriptor. In short,  file-descriptor is

  1. Low/Kernel level handler
  2. passe to read() and write() of UNIX System Calls
  3. Doesn’t include buffering and such features
  4. Less portable and lacks efficiency
  5. It’s some what OS specific so its not part of standard c programming language.

File Pointer :

“A FILE pointer is a C standard library-level construct, used to represent a file. The FILE wraps the file descriptor, and adds buffering and other features to make I/O easier.”

FILE *fp = fopen("mr32.txr","r");

When you write this then you are using file pointer. file pointer is

  1. It is high level interface
  2. Passed to fread() and fwrite() functions
  3. Includes buffering,error indication and EOF detection,etc.
  4. Provides higher portability and efficiency.
  5. It’s  part of standard c programming language.

see also

Convert file descriptor to file pointer | Convert file pointer to file descriptor in Linux by C programming

hey I am an Artist who love to write code...! Well I am an EC graduate From Ganpat University and now i am working as Embedded software engineer in one private firm.. find me at here Jeegar Patel

1 Comment to Whats is difference between file descriptor and file pointer?

Leave a Reply

Your email address will not be published. Required fields are marked *