Home / C Programming / Structures, Unions, Enums :: Discussion

Discussion :: Structures, Unions, Enums

  1. If the following structure is written to a file using fwrite(), can fread() read it back successfully?

    
     struct emp
     {   
        char *n;    
        int age;
     };
     struct emp e={"Freshergate};
     FILE *fp; 
     fwrite(&e, sizeof(e), 1, fp); 
    

     

  2. A.

    Yes

    B.

    No

    View Answer

    Workspace

    Answer : Option B

    Explanation :

    Since the structure contain a char pointer while writing the structure to the disk using fwrite() only the value stored in pointer n will get written. so fread() fails to read.


Be The First To Comment