top of page

03 Variables

Arrays

An array is a collection of variables that are accessed with an index number. Arrays in the C programming language, on which Arduino is based, can be complicated, but using simple arrays is relatively straightforward.


// Declare an array of a given length without initializing the values:


  int myInts[6];

 

  // Declare an array without explicitly choosing a size (the compiler

  // counts the elements and creates an array of the appropriate size):


  int myPins[] = {2, 4, 8, 3, 6, 4};

 

  // Declare an array of a given length and initialize its values:


  int mySensVals[5] = {2, 4, -8, 3, 2};

 

  // When declaring an array of type char, you'll need to make it longer

  // by one element to hold the required the null termination character:


  char message[6] = "hello";



© 2021 Odyssey Navigator. All rights reserved.

bottom of page