0% found this document useful (0 votes)
4 views2 pages

Array - Guía de Referencia de Arduino

The document provides a reference guide on arrays in Arduino programming, explaining their structure and how to declare and access them. It highlights the importance of zero indexing and the potential issues of accessing out-of-bounds elements. Additionally, it discusses the use of arrays within for loops for manipulation and retrieval of values.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Array - Guía de Referencia de Arduino

The document provides a reference guide on arrays in Arduino programming, explaining their structure and how to declare and access them. It highlights the importance of zero indexing and the potential issues of accessing out-of-bounds elements. Additionally, it discusses the use of arrays within for loops for manipulation and retrieval of values.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

5/5/25, 1:33 PM array - Guía de Referencia de Arduino

PROFESSIONAL E D U C AT I O N STORE Search on Arduino.cc SIGN IN

H A R D WA R E S O F T WA R E CLOUD D O C U M E N TAT I O N COMMUNITY BLOG ABOUT

This page is also available in 3 other languages Change language Español

LENGUA JE Reference > Language > Variables > Data types > Array

FUNCIONES
array
VA R I A B L E S
[Data Types]
ESTRUCTURA

LIBRERIAS Description
IOT CLOUD API An array is a collection of variables that are accessed with an index number. Arrays in the
GLOSARIO programming language, on which Arduino is based, can be complicated, but using simple
arrays is relatively straightforward.
El testo de Referencia de
Arduino tiene licencia Creative
Commons Attribution-Share
Alike 3.0.
Creating (Declaring) an Array
Encontraste algo que pueda ser All of the methods below are valid ways to create (declare) an array.
mejorado? Sugerir correcciones
y nueva documentación vía
GitHub. int myInts[6];
int myPins[] = {2, 4, 8, 3, 6};
Dudas en como usar Github? int mySensVals[6] = {2, 4, -8, 3, 2};
Aprende todo lo que necesitas char message[6] = "hello";
saber en este tutorial.
You can declare an array without initializing it as in myInts.
In myPins we declare an array without explicitly choosing a size. The compiler counts the
elements and creates an array of the appropriate size.
Finally you can both initialize and size your array, as in mySensVals. Note that when
declaring an array of type char, one more element than your initialization is required, to
the required null character.

Accessing an Array

Arrays are zero indexed, that is, referring to the array initialization above, the first eleme
the array is at index 0, hence
Last Revision: 2017/12/03
mySensVals[0] == 2, mySensVals[1] == 4, and so forth.
Last Build: 2024/11/08

It also means that in an array with ten elements, index nine is the last element. Hence:
EDITAR ESTA PAGINA
int myArray[10]={9,3,2,4,3,2,7,8,9,11};
// myArray[9] contains 11
// myArray[10] is invalid and contains random information (other memory address)

For this reason you should be careful in accessing arrays. Accessing past the end of an ar
(using an index number greater than your declared array size - 1) is reading Help
from memor
that is in use for other purposes. Reading from these locations is probably not going to d

https://www.arduino.cc/reference/es/language/variables/data-types/array/ 1/2
5/5/25, 1:33 PM array - Guía de Referencia de Arduino

much except yield invalid data. Writing to random memory locations is definitely a bad id
PROFESSIONAL E D U C AT I O N STORE Search on Arduino.cc SIGN IN
and can often lead to unhappy results such as crashes or program malfunction. This can
H A R D WA R E S O F T WAbe
RE a difficult
C L O U Dbug to
D Otrack
C U M Edown.
N TAT I O N COMMUNITY BLOG ABOUT

Unlike BASIC or JAVA, the C compiler does no checking to see if array access is within lega
bounds of the array size that you have declared.

To assign a value to an array:

mySensVals[0] = 10;

To retrieve a value from an array:

x = mySensVals[4];

Arrays and FOR Loops

Arrays are often manipulated inside for loops, where the loop counter is used as the inde
for each array element. For example, to print the elements of an array over the serial po
you could do something like this:

int i;
for (i = 0; i < 5; i = i + 1) {
Serial.println(myPins[i]);
}

Example Code

For a complete program that demonstrates the use of arrays, see the (Knight Rider exam
from the (Tutorials).

See also
LANGUAGE PROGMEM

Back to top

Trademark Help Center NEWSLETTER FOLLOW US

Contact Us Whistleblowing
Enter your email to sign up SUBSCRIBE
Distributors Digital Services Act

Careers

© 2025 Arduino Terms Of Service Privacy Policy Security Cookie Settings

Help

https://www.arduino.cc/reference/es/language/variables/data-types/array/ 2/2

You might also like