Question
#include<stdio.h>
int main()
{
FILE *fp1, *fp2;
fp1=fopen("file.c", "w");
fp2=fopen("file.c", "w");
fputc('A', fp1);
fputc('B', fp2);
fclose(fp1);
fclose(fp2);
return 0;
}
What will be the content of 'file.c' after executing the following program?
#include<stdio.h>
int main()
{
FILE *fp1, *fp2;
fp1=fopen("file.c", "w");
fp2=fopen("file.c", "w");
fputc('A', fp1);
fputc('B', fp2);
fclose(fp1);
fclose(fp2);
return 0;
}
Answer: Option A
Was this answer helpful ?
Here fputc('A', fp1); stores 'A' in the file1.c then fputc('B', fp2); overwrites the contents of the file1.c
with value 'B'. Because the fp1 and fp2 opens the file1.c in write mode.
Hence the file1.c contents is 'B'.
Was this answer helpful ?
More Questions on This Topic :
Question 2.
Out of fgets() and gets() which function i....
Submit Solution