C Language: fread function(Read Block from File)

In the C Programming Language, the fread function reads nmemb elements (each element is the number of bytes indicated by size) from the stream pointed to by stream and stores them in ptr.


The syntax for the fread function in the C Language is:

size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);

Parameters or Arguments


The array where the elements will be stored.


The size of each element in bytes.


The number of elements to read.


The stream to read.


The fread function returns the number of elements read. The fread function will return zero if nmemb is zero or size is zero.

Required Header

In the C Language, the required header for the fread function is:

#include <stdio.h>

Applies To

In the C Language, the fread function can be used in the following versions:

  • ANSI/ISO 9899-1990

stdio.h Functions