1 / 4

Introduction to compilers Lecture 24 (Prepared By : HAYA SAMMA’ANEH) Array

Introduction to compilers Lecture 24 (Prepared By : HAYA SAMMA’ANEH) Array . 1- Ordered Sequence of objects (of same type). 2- Composite object : - Built from separate objects that can be individually accessed. 3- Declaration: - a : array [1 . . 10] of integer .

waseem
Télécharger la présentation

Introduction to compilers Lecture 24 (Prepared By : HAYA SAMMA’ANEH) Array

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to compilersLecture 24 (Prepared By : HAYA SAMMA’ANEH) Array 1- Ordered Sequence of objects (of same type). 2- Composite object : - Built from separate objects that can be individually accessed. 3- Declaration: - a : array [1 . . 10] of integer . 4- Array reference : - a [5] . 5- Array slice : - a [1 : 5: 2 ] ---- a [1] , a [3] , a [5] .

  2. Layout a[1] a[2] a[3] a[4] a[5] a[6] a[7] a[8] ………. 1- Elements along a dimension stored in order . 2- Multidimensional arrays stored by row or column - a [1 .. 2] [ 1 .. 3] . - Row major . a[1,1] a[1,2] a[1,3] a[2,1] a[2,2] a[2,3] a[1,1] a[1,2] a[1,3] a[2,1] a[2,2] a[2,3] a[3,1] a[3,2] a[3,3] Row 1 Row 2 - Column major a[1,1] a[2,1] a[3,1] a[1,2] a[2,2] a[3,2] Column 1 Column 2

  3. Accessing an Element 1- Address of a [i] - ( i - lower_ bound )* w + base - if lower_ bound=0 i * w + base 2- Address of a [i , j] - Row major ( i - low1 ) * w1 +( j - low2 )* w2+ base. . w1 is width of row , w2 is width of element . 3- Multiplication is big cost.

  4. C Pointers and Arrays 1- C pointers can point to array elements . 2- Programmers perform pointer arithmetic to access elements . 3- in simple cases , eliminate multiplications by repeated addition. - for i := 1 to 10 do f (a [i]) - for i := 1 to 10 do f ( i * 4 + & a ) - for ( p= & a , i = 1 ; i <= 10 ; i++ ; p++ ) f ( p ) 4- But a compiler can perform optimization also - for ( p = & a ; p<= & a + 40 ; p++ ) f ( p )

More Related