lec1300_7

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

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

View Full Document Right Arrow Icon
Swinburne University of Technology 1 HES1300 C Programming Lecture Notes – Part 7 Swinburne University of Technology Arrays s 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. s 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. s An array will store a number of items, each of which can be retrieved via an index. Swinburne University of Technology Arrays s Arrays can be defined with different capacities, and different topology’s. s To define an array of integers, the variable declaration looks like this: s int Name[…]; s Where … is the number of integers which can be stored in the array. s For example, an array of 10 integers is defined like this: s int Store[10]; Swinburne University of Technology Arrays s To access an element of an array, you simply refer to the element’s position. s 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. s 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. s For example, we can say Store[0]=Store[1] + Store [2]; Swinburne University of Technology Arrays s 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 s The staff pigeon holes in the department are laid out in
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/29/2010 for the course C++ c taught by Professor Lauren during the Three '10 term at Swinburne.

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 Right Arrow Icon
Ask a homework question - tutors are online