this is the correct way to define a global array
or
int numbers[3][2]={{0,0},{1,1},{2,2}};
when you declare numbers[3] there will be 3 elements, element 0, element 1 and element 2, so when trying to access the first slot, you do: numbers[0]=something; for slot number 3 it would be: numbers[2]=something;
Quote: "But this produces a compile error about trying to redefine the size of the array:"
you are not redefining the size of the array there, you are simply assigning a value 3 times to the same slot. to redefine an arrays size you must delete it and make it again, there are other classes that can have this caracteristic though.
the size is defined by the number between []
int numbers[size goes here];
if you do not specify what this array contains, and is a global variable, the compiler will fill it with zeros.
for example, if you were to make a global array of 10 ints it would go like this:
int GlobalArray[10]={9,2,3,1,6,5,5,99,100,2045};
suppose that arrays are like a lot of variables with the same name, only with a different number.
all of these variables for example
int var1=0;
int var2=28;
int var3=10234;
could be contained in an array of ints like so:
and to access this array, you would use
var[0]=99999;//to change that 0 to 99999
var[1]=something;//to change that 28 to something
var[2]++;//to add 1 to 10234
this, can only be done inside a method because there would be no sense on declaring a variable as any number and adding another number before it is even used. and besides, nothing outside a method or function or class can be executed besides the declaration of variables
hi