Array data structure
In programming languages, an array is a way of storing several items (such as integers). These items must have the same type[1] (only integers, only str…
In programming languages, an array is a way of storing several items (such as integers). These items must have the same type[1] (only integers, only strings, ...) because an array can not store different kinds of items. Every item in an array has a number so the programmer can get the item by using that number.[1][2] This number is called the index.[2][3] In most programming languages, the first item has index 0, the second item has index 1 and so on.
When the programmer creates an array, they must give the size of the array. This is the number of items that can be stored in the array. If the programmer wants to store more items, then they must create a new array. This is because the size of an array can not be changed.
Arrays in C
In the programming language C, arrays can be created like this:
int array[5];
This creates an array of integers and it can store 5 integers. The programmer can now store integers in the array by doing:
array[0] = 1;
array[1] = 18;
array[2] = 5;
array[3] = 33;
array[4] = 50;
The programmer can use a value in the array like this:
int k = 3 + array[3]; // k is now 3 + 33 = 36
Arrays in Java
In the programming language Java, arrays can be created like this:
int[] array = new int[5];
This creates an array of integers and it can store 5 integers. The programmer can now store integers in the array by doing:
array[0] = 1;
array[1] = 18;
array[2] = 5;
array[3] = 33;
array[4] = 50;
The programmer can use a value in the array like this:
int k = 3 + array[3]; // k is now 3 + 33 = 36
Related pages
Sources
- ↑ 1.0 1.1 "array from FOLDOC". Free On-Line Dictionary Of Computing. October 12, 2007. Retrieved December 19, 2022.
- ↑ 2.0 2.1 Paul E. Black (November 16, 2016). "array". Dictionary of Algorithms and Data Structures. Retrieved December 19, 2022.
- ↑ David Darling (August 21, 2021). "array". Encyclopedia of Science. Retrieved December 19, 2022.
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.