To stay organized, first declare globals and optionally assign values at the same time (on the same line).
So you cannot do this:
int x;
x = 2; // illegal
void setup(){
print(x);
}
…but you can assign globally at declaration, or declare, then assign later:
int x = 2;
int y;
void setup(){
y = 4;
print(x, y);
}
Arrays work the same way. That means you can do any of these things:
int a[] = new int[2]; // size now, values later
int b[]; // size later
int c[] = { 10, 20 }; // values now, sets the size
int d[] = { 30, 40 };
int e[] = { 40, 50 };
void setup(){
a[0] = 10;
a[1] = 20;
b = new int[2]; // must size first!
b[0] = 100;
b[1] = 200;
c[0] = 999; // change a value
d = new int[4]; // replace with new size (empty)
e = new int[]{ 0, 1, 2, 3}; // replace with new values, different size
}