Arrays

Arrays are very important in the Arduino world … they allow you to manage lists of values with minimal overhead. Since Arduinos are limited in their memory footprint it is important to know how to store values without using too much memory. Arrays for you to know exactly exactly how many values you are going to need

Declaring:

int myInts[6];
int myPins[] = {2, 4, 8, 3, 6};
float mySensVals[6] = {2.5, 4.0, -8.2, 3.6, 2.1};
char message[6] = "this is like a string";

Accessing:

// shows the 4th value in the list (the first is accessed with position 0)
int box = myInts[3];

Setting:

myInts[3] = 0;

Use within a For loop:

int i;
for (i = 0; i < 6; i = i + 1) {
  display.print( myPins[i] );
}

Arrays can make code much much more efficient (if a little more complicated). As an example see the Arduino Knight Rider example..

Where arrays can get *very* confusing is when they become multi-dimensional. Have a loko at these tutorials:
Using multidimensional arrays. For example:

int pinMatrix[3][3] = {
 
  {2,  3,  4  },
 
  {5,  6,  7  },
 
  {8,  9, 10  }
 
};

An array of arrays. For example:

char line0[3] = { 'a', 'b', 'c' };
char line1[3] = { 'd', 'e', 'f' };
char line2[3] = { 'g', 'h', 'i' };
char* lines[4];
char* column;
 
void setup() {
  lines[0] = line0;
  lines[1] = line1;
  lines[2] = line2;
  Serial.begin(9600);
}