|
|
|
|
|
Arrays in Java can only be declared dynamically, and we will learn later how to do this in C. In C and C++, but not in Java, arrays can also be declared just as local variables are -- at the start of a function. This takes the form:
#define SIZE 10
int somefunction(void) {
int a[5];
double b[SIZE+5];
/* etc. */
}
Now somefunction has an array of 5 ints and an array of 15 doubles declared inside it. These arrays are created (allocated) as the function is called and are destroyed (deallocated) on function return. The size of the array (inside square brackets) has to be a constant known at compile time. This is the normal way in C to create an array.
Created By Dr. Neal Wager : The University of Texas at San Antonio