What happens to FILE pointer after file is closed?

前端 未结 4 1643
天涯浪人
天涯浪人 2020-12-06 01:48

I wish to know what happens to FILE pointer after the file is closed. Will it be NULL?

Basically, I want to check if a file has already been closed before closing a

4条回答
  •  悲哀的现实
    2020-12-06 02:16

    FILE * It's a pointer to a FILE structure, when you call fclose() it will destroy/free FILE structure but will not change the value of FILE* pointer means still it has the address of that FILE structure which is now not exits.

    same things happem with any pointer getting with malloc

    int a malloc(10);
    free(a);
    

    still a will not be NULL

    in most case i always do this things

    free(a);
    a=NULL;
    

    Edit: you can not check whether its CLOSED/freed at any time. just to make sure you can assign it NULL after free/fclose so you can check its NULL or not and go ahead ..

提交回复
热议问题