Arduino Programming Language: Array

Name

Array

Description

A series of variables that are the same size and type. Each object in an array is called an array element. For example we can have an array of integers, characters and so on. 
An array is defined by a name and an index that identify it size, the number of element inside it. 
We can get an array element using an integer, for example array will return the third element of the array. 
Why the third? 
Given an array, all accessable elements are from index 0 to n-1.

Syntax

datatype array[];
array[index] = value;

Parameters

  • datatype: any variable type, e.g. int, char, float..
  • array: any valid variable name that will identify our array
  • index: identifies the n-th array element; must not exceed the length of the array-1
  • value: data to assign to the array element, must be the same datatype as the array

Returns

string 

Usage

Application

Examples

// declaring an array of integers
int numbers[] = { 10, 20, 30 };
int a = numbers[0] + numbers[1]; // Sets variable a to 30
int b = numbers[1] + numbers[2]; // Sets variable b to 50

// different ways of declaring arrays of chars
char string1[7] = {'h', 'e', 'l', 'l', 'o', '!'};
char string2[] = "hello there!";


Based on the reference originally written by Arduino Community,  wiring.org.co and  arduino.cc