What Is An Array
What Is An Array
ARRAY
The importance of using arrays for data structures is that you can
easily change the order of data by using pointers and pointers to pointers
without having to touch the original data. In the real world, pointers
typically point to a whole group of information such as a client s name,
address, phone number, and other pertinent data.
DECLARING AN ARRAY
The way to declare an array depends on the programming
language used to write your program. In Java, there are two techniques
for declaring an array. You can declare and initialize an array either
where memory is allocated at compile time or where memory is
dynamically allocated at runtime. Allocation is another way of saying
reserving memory.
Let’s begin by declaring an array where memory is reserved when
you compile your program. This technique is similar in Java, C, and C++,
except in Java you must initialize the array when the array is declared.
There are components of a statement that declares an array. These
components are a data type, an array name and the total number of
array element to create.
int grades[] = { 1, 0, 1, 0, 1, 0, 1, 1 };
The array name is the name you use within a program to reference
an array element. The array name in this example is grades . The number
within the square brackets is the total number of elements that will be in the
array.
In order to allocate memory at compile time, you must know the
number of array elements that you need. Sometimes you don’t know this,
especially if your program loads the array with data stored in a
database. The amount of data stored in a database typically fluctuates.
The data type tells the computer that each element of the array will
contain an integer data type. The data type is followed by the array name
and two values that indicate the size of each dimension used for the array.
In this case, there are three sets of four array elements.
ASSIGNING VALUES TO A MULTIDIMENSIONAL ARRAY
grades[0][0] = 1001;
You must specify the index for both dimensions. In this example, the integer
1001, which could be a student ID, is assigned to the first element of the
first set of elements in the grades array.
SUPPLEMENTARY LEARNING RESOURCES / REFERENCES
What is array? (2022, November 30). GeeksforGeeks. Retrieved August 31, 2023, from
https://www.geeksforgeeks.org/what-is-array/
Arrays in Java. (2023, January 23). GeeksforGeeks. Retrieved August 31, 2023, from
https://www.geeksforgeeks.org/arrays-in-java/