// declaring an array of integers
int numbers[] = { 90, 150, 30 };
int a, b;
void setup() {
a = numbers[0] + numbers[1]; // Sets variable a to 240
b = numbers[1] + numbers[2]; // Sets variable b to 180
}
|
// different ways of declaring arrays of chars
char string1[15];
char string2[7] = {'h', 'e', 'l', 'l', 'o', '!'};
char string3[7] = {'h', 'e', 'l', 'l', 'o', '!', '\0'};
char string4[] = "hello there!";
int a = 10;
char *string5 = new char[a+1]; // allocates an array for holding 10 characters (last position is for holding the \0 or NULL string terminator
// ...
delete [] string5; // releases the memory space allocated for string5
|