Array

Array
An array data structure is a collection of elements indexed from 0 to size-1. In most programming languages each index can be accessed using brackets[] with the index of the element you want to access between them. The size of an array is static so it can't be extended or shortened.

In Java
In Java the array data structure is a reference, so the size doesn't have to be set when you first declare it, but once you actually create the array with the 'new' operator the size can't be changed. Java also has a special for loop that can take an array and iterate through each element.

code format="java" public class Main{ public static void main(String[] args){ int[] myArray; //created a reference to an array myArray = new int[10]; //created the array

for(int x = 0; x<10; x++){ myArray[x] = x; //set a value to index x       }

int[] myOtherArray = {1,1,2,3,5,8,13,21,34,55}; //another way to declare an array for(int n: myOtherArray){ //special for-loop System.out.print(n + " "); }   } } code

In C++
In C++ you must specify the size of the array on creation. The value returned when you create the array is actually a pointer pointing to the first value of the array, so it can be iterated through with a pointer.

code format="cpp"
 * 1) include

int main{ int myArray[10]; //create the array char name[] = "Tyler"; //special character array creation int anotherArray[] = {0,1,2,3,4,5,6,7,8,9}; //another way to declare the array

for(int x = 0; x<10; x++){//simple iteration through printf("%d ", anotherArray[9-x]); }

char *ptr; ptr = name; //pointer method iteration while(ptr){ //continues until the null character printf("%c+", *ptr); ptr++; }

return 0; } code