CIS22A - Notes for Week 9, 11/18-11/21

Announcements and Reminders


Topics

Terminology

The Clock Using Reference Variables revisited


Introduction to Arrays - Chapter 7

  • concept

  • declaration

  • memory & size

  • syntax, accessing elements, indexing, segmentation fault

  • address of an array

  • initialization

int arr[5] = { 2,3,5,7,11};    => 2 3 5 7 11

int arr[5] = { 2,3};           => 2 3 0 0 0            

int arr[] = { 2,3,5,7,11};     => 2 3 5 7 11

int arr[5] = {0};              => 0 0 0 0 0

int arr[5] = {7};              => 7 0 0 0 0

Example

Examples
  • using a for loop

  • exchanging elements, swapping

  • passing an array element to a function

  • passing the array to a function

    What is the size of the array that you pass to a function?

  • passing the array as a const

  • calculating the average of an array


Cards and Decks Revisited Using Arrays

  1. Create a deck of cards

  2. Write a print function to print a card.

  3. Write a print function to print a deck.

  4. Shuffle a deck.

  5. Create a random "hand".

  6. Detect "three of a kind" in a hand.



Videos

Arrays

Create an Array Using Loops

Using Arrays in Calculations

Passing Arrays to Functions

array

size of an array

initialization

segmentaion fault

array element

array index

indexing an array

address of an array