C Arrays - University of Delaware

1

6

C Arrays

? 2007 Pearson Education, Inc. All rights reserved.

2

6.1 Introduction

 Arrays

¨C Structures of related data items

¨C Static entity ¨C same size throughout program

? 2007 Pearson Education, Inc. All rights reserved.

3

6.2 Arrays

 Array

¨C Group of consecutive memory locations

¨C Same name and type

 To refer to an element, specify

¨C Array name

¨C Position number

 Format:

arrayname[ position number ]

¨C First element at position 0

¨C n element array named c:

- c[ 0 ], c[ 1 ]...c[ n ¨C 1 ]

? 2007 Pearson Education, Inc. All rights reserved.

4

Fig. 6.1 | 12-element array.

? 2007 Pearson Education, Inc. All rights reserved.

5

6.2 Arrays

 Array elements are like normal variables

c[ 0 ] =

3;

printf( "%d", c[ 0 ] );

¨C Perform operations in subscript. If x equals 3

c[ 5 - 2 ] == c[ 3 ] == c[ x ]

? 2007 Pearson Education, Inc. All rights reserved.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download