Recap of Arrays
What We’ve Covered So Far
To declare an array:
1 |
char charArray[6]; // an array named charArray with six spaces to hold info |
To declare an array with values:
1 2 3 |
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:
1 2 3 4 5 |
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!
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:
1 2 |
charArray[6] = '!'; // Adds another ! to the end of array above by adding a value |