{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lec1300_7

# lec1300_7 - Arrays HES1300 C Programming Lecture Notes Part...

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

Swinburne University of Technology 1 HES1300 C Programming Lecture Notes – Part 7 Swinburne University of Technology Arrays square6 Up to now, the subject has been concerned with programs which rely on single variables. That is sufficient for simple numeric work, but is useless for anything else. square6 A variable stores information. It can be visualised as a box which will store a value. If a variable can be visualised as a box, then an array is a row of boxes. square6 An array will store a number of items, each of which can be retrieved via an index. Swinburne University of Technology Arrays square6 Arrays can be defined with different capacities, and different topology’s. square6 To define an array of integers, the variable declaration looks like this: square6 int Name[…]; square6 Where … is the number of integers which can be stored in the array. square6 For example, an array of 10 integers is defined like this: square6 int Store[10]; Swinburne University of Technology Arrays square6 To access an element of an array, you simply refer to the element’s position. square6 The important thing to note is that in the C language, counting always starts from 0. So the first element is element 0 and the LAST element is number 9, NOT 10. square6 So to access the fifth element, we refer to Store[4], and this can be used in exactly the same way as a normal variable. square6 For example, we can say Store[0]=Store[1] + Store [2]; Swinburne University of Technology Arrays square6 Loops are very handy when processing arrays full of information. For example, to fill all of the elements of an array with the number 0, the following code can be used: int Numbers[10]; int i=0; while(i<10) Numbers[i++]=0; Swinburne University of Technology Multidimensional Arrays square6

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

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

{[ snackBarMessage ]}

### Page1 / 3

lec1300_7 - Arrays HES1300 C Programming Lecture Notes Part...

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

View Full Document
Ask a homework question - tutors are online