Recap of Arrays

What We’ve Covered So Far

To declare an array:

char charArray[6]; // an array named charArray with six spaces to hold info

To declare an array with values:

char charArray[6] = {'h','e','l','l','o','!'};
//or
int intArray[6] = {1, 2, 3, 4, 5, 6, 7);

To insert values into an array:

charArray[0] = 'H'; 
// Capitalizes the array above by changing a value
// or
charArray[6] = '!'; 
// Adds another ! to the end of the array above by adding a value

Arrays need a null value at the end so Sparki knows when to stop!

stop sign

Programmers often use arrays to store information and then they have to write code to look through that information.

Questions and Activities to Try

1. Store your name as a character array and have Sparki print it out on the LCD.

2. Add your last name to the array above using code that looks something like this:

charArray[6] = '!'; 
// Adds another ! to the end of array above by adding a value

3. Make the array searching code with the for loop (See Searching Through Arrays above) work for your name- search through your name for a couple different letters. Then enter someone else’s name and make sure the code still works with this different name. Try this a couple different times. (Don’t worry if one of the names doesn’t have the letter Sparki is searching for, that will result in just the name being printed out.)

Next Step:

Now that we know what variables are, let’s see what you can do with them:

Next Lesson – Functions