简体   繁体   中英

If two file pointers point to the same file, is closing one of them enough?

If I have two file pointers and do the following:

FILE *f1,*f2;
f1= fopen("inputfile","r+");
f2=f1;
fclose(f2);

Is the equal operation valid, if it is, will the last line close f1 as well?

It is enough, both will be closed and both will point to a closed file.

Assigning f2=f1 doesn't do anything magical (increasing a reference count or duplicating descriptors).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM