Practice high-yield Programming & Software Development MCQs on File Input Output — Part 1 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/40 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 40 questions answered.
Question 1 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you read a character from a file in C?
Correct Answer: Option A — getc()
Detailed Academic Explanation:
The correct answer is A: getc() Let's break down why: getc() is a standard C library function specifically designed to read a single character from a file stream. It takes a file pointer (FILE*) as an argument and returns the character read (as an integer) or EOF if the end of the file is reached or an error occurs. readchar() is not a standard C function for file input. read() is a lower-level function (usually from the POSIX standard) used for reading a block of data from a file descriptor, not a single character. getchar() reads a character from standard input (stdin), which is usually the keyboard, not from a file. So, getc() is the correct function to use when you want to read a single character from a file in C.
💡Key Conceptual Anchor:File Input Output
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The given statement FILE *fptr;
Correct Answer: Option A — Defines a pointer to the pre-defined structure type FILE
Detailed Academic Explanation:
FILE is a pre-defined structure.
💡Key Conceptual Anchor:File Input Output
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What are the two predefined FILE pointers in C?
Correct Answer: Option C — stdout and stderr
Detailed Academic Explanation:
Besides the file pointers which we explicitly open by calling fopen, there are also three predefined streams. stdin is a constant file pointer corresponding to standard input, and stdout is a constant file pointer corresponding to standard output. Both of these can be used anywhere when a file pointer is called for; for example, getchar() is the same as getc(stdin) and putchar(c) is the same as putc(c, stdout). The third predefined stream is stderr. Like stdout, stderr is typically connected to the screen by default. The difference is that stderr is not redirected when the standard output is redirected.
💡Key Conceptual Anchor:File Input Output
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C, which library is used for file operations such as reading and writing files?
Correct Answer: Option A — stdio.h
Detailed Academic Explanation:
stdio.h is the correct answer to “In C, which library is used for file operations such as reading and writing files”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to open a file in C for writing?
Correct Answer: Option A — fopen()
Detailed Academic Explanation:
fopen() is the correct answer to “Which function is used to open a file in C for writing”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does 'FILE' represent in C when working with files?
Correct Answer: Option D — A file structure
Detailed Academic Explanation:
A file structure is the correct answer to “What does 'FILE' represent in C when working with files”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you check if a file was opened successfully in C?
Correct Answer: Option B — Check the return value of fopen()
Detailed Academic Explanation:
Check the return value of fopen() is the correct answer to “How do you check if a file was opened successfully in C”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to write data to a file in C?
Correct Answer: Option A — fwrite()
Detailed Academic Explanation:
fwrite() is the correct answer to “Which function is used to write data to a file in C”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the difference between 'r' and 'w' modes when opening a file in C?
Correct Answer: Option D — 'r' is for reading and 'w' is for writing, overwriting an existing file
Detailed Academic Explanation:
'r' is for reading and 'w' is for writing, overwriting an existing file is the correct answer to “What is the difference between 'r' and 'w' modes when opening a file in C”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the 'fprintf' function in C?
Correct Answer: Option A — To format and write data to a file
Detailed Academic Explanation:
To format and write data to a file is the correct answer to “What is the purpose of the 'fprintf' function in C”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to close a file in C?
Correct Answer: Option B — fclose()
Detailed Academic Explanation:
fclose() is the correct answer to “Which function is used to close a file in C”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C, what is the function of the 'feof' function?
Correct Answer: Option A — To check if the file has reached the end
Detailed Academic Explanation:
To check if the file has reached the end is the correct answer to “In C, what is the function of the 'feof' function”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to move the file pointer to a specific position in a file?
Correct Answer: Option A — fseek()
Detailed Academic Explanation:
fseek() is the correct answer to “Which function is used to move the file pointer to a specific position in a file”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the 'rewind' function in C?
Correct Answer: Option B — To reset the file pointer to the beginning
Detailed Academic Explanation:
To reset the file pointer to the beginning is the correct answer to “What is the purpose of the 'rewind' function in C”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to read a line of text from a file in C?
Correct Answer: Option C — fgets()
Detailed Academic Explanation:
fgets() is the correct answer to “Which function is used to read a line of text from a file in C”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the 'fread' function in C do?
Correct Answer: Option A — Reads binary data from a file
Detailed Academic Explanation:
Reads binary data from a file is the correct answer to “What does the 'fread' function in C do”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to rename a file in C?
Correct Answer: Option A — rename()
Detailed Academic Explanation:
rename() is the correct answer to “Which function is used to rename a file in C”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C, what does the 'feof' function return if the end of the file is reached?
Correct Answer: Option D — EOF
Detailed Academic Explanation:
EOF is the correct answer to “In C, what does the 'feof' function return if the end of the file is reached”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you check if a file exists in C?
Correct Answer: Option B — Check the return value of fopen()
Detailed Academic Explanation:
Check the return value of fopen() is the correct answer to “How do you check if a file exists in C”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the 'ftell' function in C?
Correct Answer: Option A — To find the current position of the file pointer
Detailed Academic Explanation:
To find the current position of the file pointer is the correct answer to “What is the purpose of the 'ftell' function in C”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to write a character to a file in C?
Correct Answer: Option A — putc()
Detailed Academic Explanation:
putc() is the correct answer to “Which function is used to write a character to a file in C”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What happens if you try to open a file in 'r' mode that doesn't exist in C?
Correct Answer: Option B — An error occurs, and the file remains unchanged
Detailed Academic Explanation:
An error occurs, and the file remains unchanged is the correct answer to “What happens if you try to open a file in 'r' mode that doesn't exist in C”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you read a string from a file in C?
Correct Answer: Option D — fgets()
Detailed Academic Explanation:
fgets() is the correct answer to “How do you read a string from a file in C”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the 'remove' function in C do?
Correct Answer: Option A — Deletes a file
Detailed Academic Explanation:
Deletes a file is the correct answer to “What does the 'remove' function in C do”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C, what is the purpose of the 'fflush' function?
Correct Answer: Option B — To flush the standard output buffer
Detailed Academic Explanation:
To flush the standard output buffer is the correct answer to “In C, what is the purpose of the 'fflush' function”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to create a new directory in C?
Correct Answer: Option C — mkdir()
Detailed Academic Explanation:
mkdir() is the correct answer to “Which function is used to create a new directory in C”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you write an integer to a file in C?
Correct Answer: Option B — fprintf()
Detailed Academic Explanation:
fprintf() is the correct answer to “How do you write an integer to a file in C”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the return value of 'putc' if it fails to write a character to a file in C?
Correct Answer: Option D — EOF
Detailed Academic Explanation:
EOF is the correct answer to “What is the return value of 'putc' if it fails to write a character to a file in C”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to read and write data in binary mode in C?
Correct Answer: Option A — fread()
Detailed Academic Explanation:
fread() is the correct answer to “Which function is used to read and write data in binary mode in C”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the 'fileno' function in C?
Correct Answer: Option A — To find the file number associated with a file
Detailed Academic Explanation:
To find the file number associated with a file is the correct answer to “What is the purpose of the 'fileno' function in C”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The function fprintf is used in the program ...........
Correct Answer: Option C — When the output is to be printed on to a file.
Detailed Academic Explanation:
When the output is to be printed on to a file. is the correct answer to “The function fprintf is used in the program ...........”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which one of the following is valid for opening a read-only ASCII file?
Correct Answer: Option E — fopen(filename, "r")
Detailed Academic Explanation:
fopen(filename, "r") is the correct answer to “Which one of the following is valid for opening a read-only ASCII file”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Choose the correct difference between getc() and fgetc().
Correct Answer: Option C — if it is a macro, it may evaluate stream more than once
Detailed Academic Explanation:
if it is a macro, it may evaluate stream more than once is the correct answer to “Choose the correct difference between getc() and fgetc().”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
. . . . . . . . is an optional argument that gives the maximum number of characters to be read.
Correct Answer: Option B — width
Detailed Academic Explanation:
width is the correct answer to “. . . . . . . . is an optional argument that gives the maximum number of characters to be read.”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C code? #include <stdio.h> struct p { struct p *next; int x; }; int main() { struct p* p1 = malloc(sizeof(struct p)); p1->x = 1; p1->next = malloc(sizeof(struct p)); printf("%d\n", p1->next->x); return 0; }
Correct Answer: Option C — Somegarbage value
Detailed Academic Explanation:
Somegarbage value is the correct answer to “What will be the output of the following C code? #include <stdio.h> struct p { struct p *next; int x; }; int main() { struct p* p1 = malloc(sizeof(struct p)); p1->x = 1; p1->next = malloc(sizeof(struct p)); printf("%d\n", p1->next->x); return 0; }”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
If the conversion characters of int d, i, o, u and x are preceded by h, it indicates?
Correct Answer: Option B — A pointer to short
Detailed Academic Explanation:
A pointer to short is the correct answer to “If the conversion characters of int d, i, o, u and x are preceded by h, it indicates”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which among the following mathematical function do not have a "double" return-type?
Correct Answer: Option A — srand(x)
Detailed Academic Explanation:
srand(x) is the correct answer to “Which among the following mathematical function do not have a "double" return-type”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following function compares 2 strings with case-insensitively?
Correct Answer: Option C — strcasecmp(s, t)
Detailed Academic Explanation:
strcasecmp(s, t) is the correct answer to “Which of the following function compares 2 strings with case-insensitively”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is FILE reserved word?
Correct Answer: Option D — It is a type name defined in stdio.h
Detailed Academic Explanation:
It is a type name defined in stdio.h is the correct answer to “What is FILE reserved word”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C code? #include <stdio.h> #include <math.h> int main() { unsigned int i = -1; printf("%f\n", fabs(i)); return 0; }
Correct Answer: Option D — None of the mentioned
Detailed Academic Explanation:
None of the mentioned is the correct answer to “What will be the output of the following C code? #include <stdio.h> #include <math.h> int main() { unsigned int i = -1; printf("%f\n", fabs(i)); return 0; }”. This question is standard in competitive examination syllabi for File Input Output.
💡Key Conceptual Anchor:File Input Output
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.