Example of File Pointer

C




// C Program to demonstrate the file pointer
#include <stdio.h>
  
int main()
{
    // declaring file pointer
    FILE* fptr;
  
    // trying to get the size of FILE datatype.
    printf("Size of FILE Structure: %d bytes",
           sizeof(FILE));
  
    return 0;
}


Output

Size of FILE Structure: 216 bytes

C File Pointer

A file pointer is a variable that is used to refer to an opened file in a C program. The file pointer is actually a structure that stores the file data such as the file name, its location, mode, and the current position in the file. It is used in almost all the file operations in C such as opening, closing, reading, writing, etc.

Similar Reads

Syntax

FILE *ptr;...

Example of File Pointer

C // C Program to demonstrate the file pointer #include    int main() {     // declaring file pointer     FILE* fptr;        // trying to get the size of FILE datatype.     printf("Size of FILE Structure: %d bytes",            sizeof(FILE));        return 0; }...

How File Pointer Works in C?

...

Conclusion

We use a file pointer to refer to the file opened using fopen() function and the behavior of a file pointer can vary depending on the access modes specified when opening the file using the fopen() function....