Question
1)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
1)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?
#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);
}
======
2)Consider the variable declaration below. Write code that opens a file for output and uses a single line of code to write out all of the declared variable(s). struct inventory {
char name[30];
int count;
float price;
} log[75];
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started