lecture05 - Last time Introduction to Low-Level Programming...

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

View Full Document Right Arrow Icon
Introduction to Low-Level Programming Concepts CMSC 212 ecture 5 1 CMSC 212 Lecture 5 September 15, 2009 Last time Chapter 4, Statements switch statements Chapter 8, Arrays – arrays and array parameters – passing array sizes to functions rray initialization (one imensional and two imensional) 2 CMSC 212 – array initialization (one-dimensional and two-dimensional) Reading Read Chapter 5 in Reek (Pointers on C) 3 CMSC 212 Chapter 8, Arrays, con't. 4 CMSC 212
Background image of page 1

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

View Full DocumentRight Arrow Icon
Multidimensional array parameters and arguments The first dimension of any array parameter, in a prototype and function definition, does not need a size specified (it is ignored even if present) Regardless of the size of an array parameter's first imension, ny rray of the same element type nd 5 CMSC 212 dimension, any array of the same element type and the same sizes for the remaining dimensions can be passed in as an argument Multidimensional array parameter example #include <stdio.h> int sum_row(int arr[][3], int row); int sum_row(int arr[][3], int row) { int i, sum= 0; for (i= 0; i < 3; i++) sum += arr[row][i]; eturn sum; 6 CMSC 212 return sum; } int main() { int arr1[4][3]= {{7, 5}, {3, 1, 8}, {6}}; int arr2[5][3]= {7, 5, 3, 1, 8, 6, 4, 2}; printf("%d\n", sum_row(arr1, 1)); printf("%d\n", sum_row(arr2, 2)); return 0; } Symbolic constants The #define preprocessor directive is convenient when arrays are used Syntax: #define name value Everywhere that name appears between the #define and the end of the file the preprocessor
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.

This note was uploaded on 11/23/2009 for the course CMSC 212 taught by Professor Staff during the Spring '08 term at Maryland.

Page1 / 5

lecture05 - Last time Introduction to Low-Level Programming...

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