C PROGRAMMING File Pointers
C PROGRAMMING File Pointers
Syntax:
The syntax of pointers is similar to the variable declaration in C, but we use the ( * )
dereferencing operator in the pointer declaration.
datatype * ptr;
where,
ptr is the name of the pointer.
datatype is the type of data it is pointing to.
POINTER ARRITHEMATICS IN C
• For Example:
int arr[3] = {1, 2, 3};
int *ptr = arr; // ptr points to the first element of the array
ptr++; // ptr now points to the second element of the array
arrays.
INCREMENT/ DECREMENT OF A POINTER
• For Example:
• malloc :
Allocates a specified number of bytes and returns a pointer to the first byte.
• calloc :
Allocates memory for an array of elements, initializes them to zero.
• realloc :
Resizes the memory block pointed to by the pointer.
• free (Deallocation):
Frees the allocated memory.
FILE POINTERS
• DECLARATION:
FILE *filePointer;
• Writing to Files:
Functions like fputc, fputs and fprintf are used to write data to a file.
Ex:
fprintf(fp, "Hello, World!");
WORKING WITH FILE POINTERS
• rewind() : It is used to move the file pointer to the beginning of the file .
Syntax :
rewind(FILE *stream);