Write out the file contents for out 2 as produced by the fol
Write out the file contents for out 2 as produced by the following code. Give specific values to bytes or ranges of bytes. The values of the same variable are being written using fprintf() and then fwrite(). How many bytes are written by each, and which is more efficient? # include main () { FILE *fpt; struct frog { float d; int x; } henry; henry .d = 12.73; henry .x = 81925; fpt = fopen (\"out2\", \"W\"); fprintf (fpt, \"57, 2f %7d\ \", henry .d, henry .x); fwrite (&henry;, sizeof (struct frog), 1, fpt); fclose (fpt); }
Solution
The contents of out2 as produced by the code is:
8 bytes are used by struct frog henry as sizeof(struct frog) = 8 bytes
sizeof(12.73) = 8 bytes
sizeof(81925) = 4 bytes
total = 12 bytes
Thus structure variable is more efficient than individual variable storage.
