Er a can be used as a pointer to array element 0 type

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: + 20 double a[3]; x x + 8 x + 16 x + 24 IA32 char *p[3]; x x + 4 x + 8 x + 12 x86- 64 x x + 8 x + 16 x + 24 3 ARRAY ACCESS ¢༊  Basic Principle T A[L]; —༉  Array of data type T and length L —༉  Iden?fier A can be used as a pointer to array element 0: Type T* 1 int val[5]; x ¢༊  Reference val[4] val val+1 &val[2] val[5] *(val+1) val + i 5 x + 4 2 x + 8 Type 3 x x + 4 x + 8 ?? 5 x + 4 i x + 12 3 x + 16 x + 20 Value int int int int int int int 1 * * * * 4 ARRAY EXAMPLE #define ZLEN 5 typedef int zip_dig[ZLEN]; zip_dig cmu = { 1, 5, 2, 1, 3 }; zip_dig mit = { 0, 2, 1, 3, 9 }; zip_dig ucb = { 9, 4, 7, 2, 0 }; 1 zip_dig cmu; 16 20 0 zip_dig mit; 36 56 ¢༊  2 24 2 40 9 zip_dig ucb; ¢༊  5 28 1 44 4 60 1 32 3 48 7 64 3 9 52 2 68 36 56 0 72 76 Declara?on “zip_dig cmu” equivalent to “int cmu[5]” Example arrays were allocated in successive 20 byte blocks —༉  Not guaranteed to happen...
View Full Document

This document was uploaded on 04/05/2014.

Ask a homework question - tutors are online