C Programming - Input / Output - Discussion

Discussion Forum : Input / Output - General Questions (Q.No. 6)
6.
Which files will get closed through the fclose() in the following program?
#include<stdio.h>

int main()
{
    FILE *fs, *ft, *fp;
    fp = fopen("A.C", "r");
    fs = fopen("B.C", "r");
    ft = fopen("C.C", "r");
    fclose(fp, fs, ft);
    return 0;
}
"A.C" "B.C" "C.C"
"B.C" "C.C"
"A.C"
Error in fclose()
Answer: Option
Explanation:

Extra parameter in call to fclose().

Discussion:
27 comments Page 3 of 3.

Vivek Shivhare said:   10 years ago
Yes it is true to write "return (a, b, c)" it will returns the right most value (e.g c).

The reason is return and fclose both are predefined functions theirs properties are designed by devlopers. Which are different.

fclose is file operation function so it is different than return.
(1)

Yuvasree said:   9 years ago
Yes, correct answer is D, It will get error message as too many arguments to function fclose. Because according fclose syntax we can pass only one argument.

Pranathi said:   8 years ago
'fclose()' takes only one argument at a time i.e it can't be used to close multiple opened file at a time.
(3)

Venkat said:   7 years ago
Please explain it in a simple way.

Rajan said:   5 years ago
@All.

The code should be;

#include<stdio.h>
int main ()
{
FILE *fs, *ft, *fp;
fp = fopen("ABC", "r");
fs = fopen("ACD", "r");
ft = fopen("ADF", "r"); = fclose(fp, fs, ft);
return 0;
}
A - "ABC"
B- "ACD"

Pratyush sharma said:   3 years ago
Option D will be the Right answer because you can not pass more than one argument in function.
(1)

Snegha m d said:   1 year ago
The correct answer is D.


Post your comments here:

Your comments will be displayed after verification.