1. Homepage
  2. Exam
  3. COMP2017/9017 System Programming - Sample Exam - Q5 Memory

COMP2017/9017 System Programming - Sample Exam - Q5 Memory

This question has been solved
Engage in a Conversation

Question 5 (Memory) (15 marks)

  CourseNana.COM

Write the memory contents after execution of all statements up to line 17. Write the names of each variable, its address and any data associated with them in the appropriate box. CourseNana.COM

  CourseNana.COM

1 extern void *lerp(void *); CourseNana.COM

2 struct tee { CourseNana.COM

3 int x; CourseNana.COM

4 void* m; CourseNana.COM

5 void *p; CourseNana.COM

6 }; CourseNana.COM

7 struct tee t; CourseNana.COM

8 int main( int argc , char ** argv ) { CourseNana.COM

9 int a = 73; CourseNana.COM

10 static void *(* flerp )( void *) = lerp; CourseNana.COM

11 t.x = 51; CourseNana.COM

12 t.m = &a; CourseNana.COM

13 struct tee s = t; CourseNana.COM

14 s = *((struct tee*)(flerp((void*)&t))); CourseNana.COM

15 t.p = &s; CourseNana.COM

16 printf("%s\n", (const char *)&a); CourseNana.COM

17 // show snapshot of memory at this statement CourseNana.COM

  CourseNana.COM

The starting address for each segment of memory has been provided for you. For the purpose of this exam, you should assume that memory is allocated positively from 0x0000 to 0xFFFF. CourseNana.COM

  CourseNana.COM

sizeof(char) is 1 byte and sizeof(char *) is 4 bytes. The ASCII value of ’A’ is 65. Assume memory does not align to nearest word size. CourseNana.COM

  CourseNana.COM

Consider these two lines of code, the memory contents may look like −! CourseNana.COM

char a = 5; CourseNana.COM

char *b = &a; CourseNana.COM

  CourseNana.COM

Sample memory CourseNana.COM

0x7000 a 5 CourseNana.COM

0x7001 b 0x7000 CourseNana.COM

  CourseNana.COM

  CourseNana.COM

Program code CourseNana.COM

0x2000 CourseNana.COM

  CourseNana.COM

  CourseNana.COM

Static/Global CourseNana.COM

0x3000 CourseNana.COM

  CourseNana.COM

  CourseNana.COM

Heap CourseNana.COM

0x4000 CourseNana.COM

  CourseNana.COM

  CourseNana.COM

Stack CourseNana.COM

0x7000 CourseNana.COM

  CourseNana.COM

Get the Solution to This Question

WeChat WeChat
Whatsapp WhatsApp
System Programming代写,C Language代写,Memory代写,Pointer代写,System Programming代编,C Language代编,Memory代编,Pointer代编,System Programming代考,C Language代考,Memory代考,Pointer代考,System Programminghelp,C Languagehelp,Memoryhelp,Pointerhelp,System Programming作业代写,C Language作业代写,Memory作业代写,Pointer作业代写,System Programming编程代写,C Language编程代写,Memory编程代写,Pointer编程代写,System Programmingprogramming help,C Languageprogramming help,Memoryprogramming help,Pointerprogramming help,System Programmingassignment help,C Languageassignment help,Memoryassignment help,Pointerassignment help,System Programmingsolution,C Languagesolution,Memorysolution,Pointersolution,