Arduino build error

error: too many initializers for 'int [3]'

The array was declared with room for a number of items and the braces hold more. Text arrays have the same limit, and the text needs one extra place for its end mark.

  • Build error
  • 2 common causes
  • Seen 487 times in failed builds on Mokxi in the 30 days to November 16, 2026.
The message

What the Arduino IDE prints

Output window
sketch.ino: In function 'void setup()':
sketch.ino:3:30: error: too many initializers for 'int [3]'
    3 |   int values[3] = {1, 2, 3, 4};
exit status 1

Make the array bigger, or let the compiler count: leave the size out.

Mokxi's compiler, clang, words it as excess elements in array initializer.

Causes

The 2 usual causes with the fix

1More values than the declared size

int values[3] holds three items. Declare room for all of them, or write int values[] and let the compiler count.

Broken
void setup() {
  Serial.begin(9600);
  int values[3] = {1, 2, 3, 4};
  Serial.println(values[2]);
}

void loop() {
}
Fixed
void setup() {
  Serial.begin(9600);
  int values[] = {1, 2, 3, 4};
  Serial.println(values[3]);
}

void loop() {
}

Try this fix in Mokxi

2A text longer than its char array

A char array needs one place per letter plus one for the zero that ends the text. "Mokxi" needs six.

Broken
void setup() {
  Serial.begin(9600);
  char name[5] = "Mokxi";
  Serial.println(name);
}

void loop() {
}
Fixed
void setup() {
  Serial.begin(9600);
  char name[6] = "Mokxi";
  Serial.println(name);
}

void loop() {
}

Mokxi’s build tab says: The text is longer than its char array.

Try this fix in Mokxi

FAQ

Questions and answers

Why does text need one extra place?

C text ends with a zero byte that marks the end. Without room for it, the printing code would run past the end.

Can I leave the size out?

Yes, when you give the values, as in int values[] = {1, 2, 3}. The compiler counts them.

Is giving fewer values an error?

No. The rest are set to zero.