EE312exam1rev8-10 - CH 8 ARRAYS Scalar variables variables...

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

View Full Document Right Arrow Icon
CH 8: ARRAYS Scalar variables : variables capable of holding a single data item Aggregate variables : can store collections of values. 2 kinds: arrays and structures (records) 8.1 One-Dimensional Arrays Array : a data structure containing a number of data values, all of which have the same type. Simplest kind has just one dimension. To declare an array must specify the type of the array’s elements and number of elements. Elements : the data values (of an array), can be individually selected by their position within the array. In one dimensional array are conceptually arranged one after another in a single row. Always numbered starting from 0 (elements of array of length n are indexed from 0 to n-1) Subscripting/Indexing the array: when accessing a particular element of an array, we write the array name followed by an integer value in square brackets. Array Initializer : a list of constant expressions enclosed in braces and separated by commas. If the initializer is shorter than the array, the remaining elements of the array are given the values 0. Illegal for initializer to be completely empty and to be longer than the array it initializes. The length of array can be omitted if initialize is present. Sizeof operator : determine the size of an array in bytes, or the size of an array element. Dividing the array size by the element size gives the length of the array. [ sizeof(a) / sizeof(a[0]) ] 8.2 Multidimensional Arrays Matrix : a two dimensional array. Int m[5][9] has 5 rows and 9 columns. Row-Major order : c stores arrays in row-major order= with row 0 first then row 1… Identity matrix : has 1’s on the main diagonal, where the row and column index are the same, and 0’s everywhere else. Const : starting declaration with const makes an array constant (1D or multidim). This documents that the program won’t change the array. Helps the complier catch errors by informing it that we don’t intent to modify the array. ( const works with any variable) CH 9: Functions Function : a series of statements that have been grouped together and given a name. Building blocks of C programs. Each function is essentially a small program, with its
Background image of page 1

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

View Full Document Right Arrow Icon
own declarations and statements. Allow us to avoid duplicating code that’s used more than once. Functions are reusable- a function originally part of one program can be used in another. Ex: main. 9.1 Defining and Calling Functions Return type : the type of data that the function returns each time it’s called. Parameters
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 7

EE312exam1rev8-10 - CH 8 ARRAYS Scalar variables variables...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online