CDA3101-F11-Quiz3-KEY

CDA3101-F11-Quiz3-KEY - WHAT IS RESULT OF&z(show work...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CDA 3101 FALL 2011 -- QUIZ #3 Fri 30 Sep 2011 Q1: (5 pts) Pointers: WHAT IS A POINTER ? WHAT DOES REFERENCING DO? Q2: (15 pts) Pointer Arithmetic GIVEN: int z[123]; int *p; x = 45; z[67] = 89 WHAT IS RESULT OF ? (show work) WHAT IS RESULT OF ? (show work) WRITE MIPS CODE FOR p = &z[67] ; *p = 99 (2-3 statements) KEY ON NEXT PAGE (NEXT SLIDE)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CDA 3101 – FALL 2011 -- QUIZ #3 – Fri 30 Sep 2011 -- ANSWER KEY Q1: (5 pts) Pointers: WHAT IS A POINTER ? -- 2pts ANS : A pointer is a variable that contains a memory address WHAT DOES REFERENCING FUNCTION “&” DO? -- 3pts ANS : The referencing operator returns the memory address of its argument (e.g., &x returns the address of variable x) Q2: (15 pts) Pointer Arithmetic GIVEN: int z[123]; int *p; x = 45; z[67] = 89
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: WHAT IS RESULT OF &z ? (show work) -- 5pts ANS: &z returns the base address in memory of the array z WHAT IS RESULT OF *(&x) ? (show work) -- 5pts ANS: *(&x) returns the contents of the memory address &x, so *(&x) = 45. WRITE MIPS CODE FOR p = &z[67] ; *p = 99 (2-3 statements) - 10 pts ANS: (1) From the givens, pointer p = &z[67] gets the address of z[67], so if the base address of z is in $s0, and p is in $t0, then we have the MIPS statement: addi $t0, $s0, 268 # since 268 = 67 * 4 (2) Assuming that the base address of z is in $s0, and p points to z[67], then *p = 99 means that z[67] 99. So we have: addi $t2, $zero, 99 #put 99 in $t0 sw $t2, 268($s0) #store $t0 in z[67]...
View Full Document

{[ snackBarMessage ]}

Page1 / 2

CDA3101-F11-Quiz3-KEY - WHAT IS RESULT OF&z(show work...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online