Question: Write out the memory map and file contents for the following code, providing all values at the end of execution. What is the exact output
Write out the memory map and file contents for the following code, providing all values at the end of execution. What is the exact output produced by this program?
Note: I need the answer in this format:
| Label | Address | Value |
| i | 400 - 403 | 5 |
#include
main() {
double testd;
int testi;
FILE *fpt;
struct frog {
double *x,y;
};
struct frog turtle,*apple,tv[3];
testi=21;
apple=&turtle;
turtle.y=5.2;
fpt=fopen("out3","w");
fwrite(apple,sizeof(struct frog),1,fpt);
fclose(fpt);
apple->x=&testd;
fpt=fopen("out3","r");
fread(&(tv[1]),sizeof(struct frog),1,fpt);
fclose(fpt);
*(turtle.x)=7.3;
(*apple).y=3.6;
turtle.y=1.5;
*(tv[1].x)=6.4;
printf("%lf ",tv[1].y);
}
===============================
Write out the file contents for out2 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,"%7.2f %7d ",henry.d,henry.x);
fwrite(&henry,sizeof(struct frog),1,fpt);
fclose(fpt);
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
