Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

Difference between File Descriptor and File Pointer

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

File descriptor is simply an index into the file descriptor table. For each process in our operating system, there is a process control block(PCB). PCB keeps track of the context of the process. So one of the fields within this is an array called file descriptor table.

This array keeps track of all the resources that the process owns and can operate on. The file descriptor table holds pointers to the resources. Resources could be

  • File
  • Terminal I/O
  • Pipes
  • Socket for the communication channel between machines
  • Any devices

So if any process opens or uses any resources will have an entry in the file descriptor table. Any process when it first starts is given access to three resources. These resources are:

  • stdin
  • stdout
  • stderr

Understand this with an example. Suppose we are working on the terminal then input for it is stdin, the output is stdout and the error is stderr. And if we open any other terminal then both are two different processes now. The newly opened terminal will have its own stdin, stdout because it’s a different process.

The file descriptor is just an integer that you get from the open() system call.

Example of file descriptor:

int fd = open(filePath, mode);

File pointer is a pointer returned by fopen() library function. It is used to identify a file. It is passed to a fread() and fwrite() function.

Example of file pointer:

FILE *fp;

fp = fopen(“sample.txt,”a”);

fprintf( fp, “Welcome to GFG”);


File pointer provides high efficiency and high portability. It is buffered, unlike the file descriptor. Generally, we use a file pointer when we are reading from a file.


Following is a table of differences between File Descriptor and File Pointer


File Pointer

File Descriptor

1.File pointer is allocated with fopen function call
FILE *fp;
fp = fopen(“sample.txt,”a”);
File descriptor is allocated with open system call
int fd = open( filePath, mode );
2.It is generally, use for the application which is doing extensive read 
or write from a file
It is generally used for the application that do frequently random access of file 
3.It is a pointerIt is an integer value like 0, 1, 2
4.The file pointer is bufferedThe file descriptor is not buffered
5.It is highly portable and efficientIt is less portable and efficient in comparison with the file pointer
6.It is passed to fread() and fwrite() functionIt is passed to read() and write() function
7.It is not suitable for inter-process communicationIt is suitable for inter-process communication
8.Library functions generally use file pointerSystem call generally use the file descriptor
9 file pointers are data structures.File descriptors are represented as integer values
10file pointers are used to represent the current position within the file. File descriptors are used to identify an open file,
11file pointers are used by the application program to read from or write to the file. File descriptors are used by the operating system to perform operations on the file,
12file pointers can have any value depending on the position within the file. File descriptors are non-negative integers, 
My Personal Notes arrow_drop_up
Last Updated : 20 Apr, 2023
Like Article
Save Article
Similar Reads