Does array make the program smaller?

You would usually group in an array things that are related for example if you have LEDs connected to pins, you could do

const byte ledPins[] = {2,3,4,5,6,7}; // pins driving my leds
const byte ledCount = sizeof ledPins / sizeof ledPins[0] ; // number of pins calculated by the compiler

which would be better than

const byte ledPin1 = 2;
const byte ledPin2 = 3;
const byte ledPin3 = 4;
const byte ledPin4 = 5;
const byte ledPin5 = 6;
const byte ledPin6 = 7;

const byte ledCount = 6;

as you don't need to modify the count manually if you add a led later on or modify the code as you can use a for loop to efficiently "talk" to all LEDs

for (byte i = 0; i < ledCount; i++) pinMode(ledPins[i] , OUTPUT);

or the fancier Range-based for loop

for (auto && aPin : ledPins) pinMode(aPin, OUTPUT);

but if you have a pin that does not "conceptually" fit in the same group, say you have also a button or a sensor connected to an analogPin, then you would declare a special constant for those.

const byte buttonPin = 8;
const byte sensorPin = A0;

and not add those into the array.

➜ keep things organised in a way that makes sense and that will help read the code. (and that would take the same amount of SRAM memory)

1 Like