How do get the array length?

MarkG:
Yes, but that still doesn't get around the fact that you can have a zero length array.

No, zero length arrays are not legal. It is a hack, and is only intended for use within a struct as a header for a variable length object. It is provided by GNU, C1 and a few others, but is not legal C or C++. Flexible arrays are different, but only available in C.

If you open your platform.txt and add -pedantic to the command line, you'll receive this error:

overwrite.ino:1: error: ISO C++ forbids zero-size array 'array'

@boguz,
To see the full extent of what your code was doing, this simple sketch will show you.
the array is only read from, the variable number is incremented.
Reading the array out of bounds has read 'number'.

int array[2] = {};
int number;
int count = 0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  ++number;
  Serial.println( array[ 2 ] );
  delay( 500 );
}