Home > Software engineering >  C error: too many initializers for 'int [2]'
C error: too many initializers for 'int [2]'

Time:01-04

I keep getting this error when declaring an int[2] array, but it looks fine to me.

error: too many initializers for 'int [2]'
 int <array_name>[2] = { 0, 255, 255 };
                                     ^

am I doing someting wrong?

CodePudding user response:

You declare the array to have two elements with [2], but you're trying to assign three numbers to it with { 0, 255, 255 }. Something's gotta give.

CodePudding user response:

You declared the size of array is 2 but gave it 3 elements, I think just change it to int <array_name>[3] will fix the problem

  •  Tags:  
  • Related