Lecture 2

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 000C 0010 0014 00 27 D0 3C 0018 001C 0020 0024 35 University of Washington Assignment in C   Leo ­hand ­side = right ­hand ­side   LHS must evaluate to a memory LOCATION   RHS must evaluate to a VALUE (could be an address)   E.g., x at locaJon 0x04, y at 0x18   x originally 0x0, y originally 0x3CD02700   int * x; int y; x = &y + 3; // get address of y add 12 // 0x0018 + 0x000C = 0x0024 *x = y; // value of y copied to // locaGon to which x points Memory 0000 24 00 00 00 0004 0008 000C 0010 0014 00 27 D0 3C 0018 001C 0020 0024 36 University of Washington Assignment in C   Leo ­hand ­side = right ­hand ­side   LHS must evaluate to a memory LOCATION   RHS must evaluate to a VALUE (could be an address)   E.g., x at locaJon 0x04, y at 0x18   x originally 0x0, y originally 0x3CD02700   int * x; int y; x = &y + 3; // get address of y add 12 // 0x0018 + 0x000C = 0x0024 *x = y; // value of y copied to // locaGon to which x points Memory 0000 24 00 00 00 0004 0008 000C 0010 0014 00 27 D0 3C 0018 001C 0020 00 27 D0 3C 0024 37 University of Washington Arrays   Arrays represent adjacent locaJons in memory storing the same type of data object   e.g., int big_array[128]; allocates 512 adjacent bytes in memory starGng at 0x00ff0000   Pointer arithmeJc can be used for array indexing in C (if pointer and array have the same type!):   int *array_ptr; array_ptr = big_array; 0x00ff0000 array_ptr = &big_array[0]; 0x00ff0000 array_ptr = &big_array[3]; 0x00ff000c array_ptr = &big_array[0] + 3; 0x00ff000c (adds...
View Full Document

This document was uploaded on 04/04/2014.

Ask a homework question - tutors are online