About C Interview Questions-Files
This C Interview Questions-Files is giving complete information about all the interview questions on File in C language including all the predefined functions to process files.
C Interview Questions-Files
What is File?
Collection of bytes stores physically(permanently)
How to process Files in C?
Using a pointer to FILE variable.
How to open a file?
fopen() function opens a file in the specified mode and returns a pointer to File that has opened.
What will be returned if file not found while opening?
In case of the read mode, it returns NULL if file not present.
In case of write mode or append mode, it creates the new file with the specified name and returns NULL
only if no memory to create a new file.
What is the use of fgetc() function?
fgetc() function is used to read a byte/character from the file and returns ASCII value of that symbol.
Why getc() function returns int type?
It returns ASCII value of byte or symbol that has read.
ASCII can be represented in integers only.
What is EOF?
A pre-defined Macro represent End of File with value -1
How to close a file stream?
fclose() function is used to close the stream.
Difference between ‘\0’ and EOF?
‘\0’ stores at the end of String
EOF represents End of File has reached in file processing.
Explain write mode?
“w” is the char* type, used to open a file to write info.
If the file is present, it opens the file and returns a pointer to file else it creates a new file.
Difference between Write mode and Append mode?
Write mode is to write the contents from starting position where as Append mode is to add the
contents at the end.
How to write a character into File?
using putc() or fputc() functions.
What is the use of getw() function?
Used to read integer data from a file.
Describe feof() functionality ?
Used to process the file data.
Returns non-zero value when the end of file has reached.
How can we read a String from a file?
using fgets() function we can read set of characters as a string from the file.
How to send the cursor position in an opened file?
Using fseek() function we can move the cursor location to perform read and write operations in the
What is the use of ftell() function?
ftell() function returns current cursor position s byte location in the opened file.
How to reset cursor position to the beginning of a file?
using rewind() function
or using fseek() function.
Can we move the file location after rename it?
Yes, it is allowed to move the file location after rename by specifying the new path.
Difference between perror() and printf() ?
perror() function used to display system messages while printing error messages.
print() function display only used message.
Describe r+ and w+ modes?
r+ is used to open a file both in read and write modes but the file should be present.
w+ is used to open a file both in read and write mode but if the file is not present, it creates the file.
What is the use of getch() function?
used to read a character from the console.
Available in conio.h header file.
How to push a character back into Stream?
Using ungetc() function we can push a character back into Stream
Difference between printf() and fprintf() ?
printf() function prints different types of data on console at a time.
fprintf() function writes different types of data into the file at a time.