CS计算机代考程序代写 0

0
80
int 4}
l siteofcinty sf fun when fun
}
int main() {
char i[10] = {¡¯h¡¯,¡¯i¡¯};
sheofffohar
SReofcichary
}
int main() {
}
int main() {
int *i;
fun(int *i) {
Sheofcint
}
int main() {
Sikof i 54
srteofce.nl y sineotcint
Sf main i isnotapointer
int i[5] = {4,5,2,5,1};
fun(i); }
int main() { 4fin int *i;
i i = malloc(sizeof(int)); }
void fun(int **i) {
main *i = malloc(sizeof(int)*7);
sf main stmcih
progend whenprogeny
whenfreedor
progends free
}
Sikofcint
7
int main() { ifint *i;
fun(&i);
free(i); }
int its e
i _Biff 12
4
onto
sireofggin
can be used as pointer tozoerote
CSC209H Worksheet: malloc Basics
1. Each time a variable is declared or memory is otherwise allocated, it is important to understand how much memory is allocated, where it will be allocated and when it will be de-allocated. Complete the table below. (Note: some of the programs allocate more than one block of memory.)
Code Fragment
int main() {
int i;
}
int fun() {
float i; }
int main() {
fun();
}
int fun(char i) {
… }
int main() {
fun(¡¯a¡¯);
4i
char *i;
Space?
sizeof(int)
Where?
stack frame for main
De-allocated when?
when program ends
whenfun returns
when fun
returns
when prog ends
4
sitcofffloat stackframe of fun
streofkhor stackframe of fun
stackframe of main
k
… returns
sun 4 28 heap
element ofthearray Iicon
heap
Sf

s
CSC209H Worksheet: malloc Basics
2. Trace the memory usage for the program below up to the point when initialize is about to return. We have set up both stack frames for you, and the location of the heap.
Section
Heap
stack frame for initialize
Address
0x23c 0x240
0x244 0x248
0x454
0x458
0x45c
0x460
0x464
0x46c
0x470
0x474
0x478
0x47c
0x480
0x484
0x488
0x48c
Value
Label
#include
#include
// Initialize two parallel lists.
void initialize(int *a1, int *a2, int n) {
for (int i = 0; i < n; i++) { a1[i] = i; a2[i] = i; } } . . int main() { int numbers1[3]; int *numbers2 = malloc(sizeof(int) * 3); initialize(numbers1, numbers2, 3); for (int i = 0; i < 3; i++) { printf("%d %d\n", numbers1[i], numbers2[i]); } free(numbers2); return 0; } stack frame for main void Ancient arr Mallock 4 I int mainC i 10 cg char dataset image i a arr Carr sizeof Lint fono.cm heap in oarr a o f ¦Ì