Array

From GCHSWiki
Jump to: navigation, search

Array- In computer science it is a data structure consisting of a group of elements that are accessed by indexing. In most programming languages each element has the same data type and the array occupies a contiguous area of storage. Most programming languages have a built-in array data type. Basically, it's a list. It is one variable that stores many things. Once created, you can't change the size of an array!

An array is an object that is used to store a list of values. It is made out of a contiguous block of memory that is divided into a number of "slots." Every slot stores a value, and all the values are of the same type. There are two types of arrays: indirect and direct. The difference between these two is that for direct, you have to create and initialize on the other hand indirect you have to create an array but not initialize it. The one thing that you can not do is change the size of the array.

There are 2 types of Arrays:

Direct- Create and initialize Arrays

ex: int x = 5; FilledRect <name> = new FilledRect( #, #, #, #, canvas) FilledRect [ ] <name> = {new FilledRect ( #, #, #, #, canvas), new FilledRect ( #, #, #, #, canvas)......};

Indirect- Creating an array but not initializing it

ex: int x; x = 5; FilledRect <name>; <name> = new FilledRect( #, #, #, #, canvas);

When describing an array, it looks like this: