Write out the file contents for out 2 as produced by the following code. Give sp
ID: 3930326 • Letter: W
Question
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); }Explanation / Answer
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.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.