452 views
0 votes
0 votes

#include<stdio.h>
int main()
{
    FILE *fp[2];
    if((fp[0]=fp[1]=fopen("test.txt","w"))!=NULL)  //test.txt file should be empty during first compiling
    {
        fputs("one",fp[0]);
        fclose(fp[0]);
        fputs("two",fp[1]);
        fclose(fp[1]);
    }
    return 0;
}

what will be printed in file “test.txt”. and also am not understanding what is done after “fputs("one",fp[0]);” and “fputs("two",fp[1]);”

can anyone tell me with explanation...please….

1 Answer

0 votes
0 votes
one will be printed.

Reason:- fp[0] and fp[1] are having same reference i.e pointing to the same buffer for writing

Now when fp[0] writes one and close the buffer thereafter fp[1] write two but it does not go into the file as it is closed by fp[0]

Related questions

0 votes
0 votes
1 answer
4
Psnjit asked Jan 12, 2019
1,138 views
main(){unsigned int i= 255;char *p= &i;int j= *p;printf("%d\n", j);unsigned int k= *p;printf("%d", k);} Both the outputs are -1. I have even tried with - int i = 255(3rd ...