Arrays, continued

715 views

Published on

Published in: Business, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
715
On SlideShare
0
From Embeds
0
Number of Embeds
386
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Arrays, continued

  1. 1. CS111 Lab Arrays, continued Instructor: Michael Gordon
  2. 2. Arrays in Functions  To write a function title with an array as a parameter, use the array declaration without the size.  Example: int func(int a[])  To call a function with an array as an argument, just use the array name.  Example: int x = func(grades)  Where int grades[] was previously declared.
  3. 3. Functions, continued  Arrays are, by default, pass by reference.  If your function needs to perform actions on the entire array, you will need to specify the array size as a parameter.  Example: int sum(int arr[], int size)
  4. 4. Two Dimensional Arrays A   2D array can be thought of in two ways: A grid/table of rows and columns of data An array of arrays  You  can declare it as follows: e.g: int arrayName[5][4];  Function call: func(arrayName)  Function title example: func(int a[][4], int rows)
  5. 5. Visualization  The grid below shows the addresses/indexes of each cell of an array c[5][4]; c[0][0] c[0][1] c[0][2] c[0][3] c[1][0] c[1][1] c[1][2] c[1][3] c[2][0] c[2][1] c[2][2] c[2][3] c[3][0] c[3][1] c[3][2] c[3][3] c[4][0] c[4][1] c[4][2] c[4][3]
  6. 6. Visualization, pop quiz  What’s the value in c[0][0]?  What’s the value in c[2][2]?  What’s the value in c[3][4]? 90 100 85 99 40 50 30 45 77 68 81 65 85 89 91 93 70 65 66 71

×