We will learn about Array data type in programming languages
An array is a data structure in Programming Languages. It is a collection of similar type of element that have continuous memory location. We can store a table of an object or primitive data type with a set of similar type of element using an array.
Array in Java is supported by index base identification, the first element of an array is stored at index 0, the last element of the array is stored at index n-1(n is array length)
When we declare the array in the programming language, we need to consider in two factors:
Syntax
Data_type Array_Name[Array_size];
Example
int marks[30]; float student_height[40]; char alphabets[26];
Array data type in programming
int marks[6];
When we declare an array, memory allocates the fixed size of space according to array size.
In the above example, we declared an array size of 6 as an integer. So, memory allocates six places for array data.
Int marks[6]={45,76,56,87,43,67}
float Height[6]={45,76,56,87,43,67}
Ways of initialization of an Array
int marks[]={34,65,78,98,43,}
34 placed to marks[0] – 1 st element
65 placed to marks[1] – 2 nd element
78 placed to marks[2]- 3 rd element
98 placed to marks[3] – 4 th element
43 placed to marks[4] – 5 th element
Code optimization – It optimizes the code. We can retrieve and sort the data easily.
Random access – We can locate any data using any index position
It is used to represent multiple data items of a similar type with a single name.
It can be used to implement other data structure such as stacks, queues, linked list, trees, graphs
Size limit – We can store only fixed size elements in the array. But, it does not increase its size during runtime.
Since the array is of fixed size, if we allocate more memory than the required size, then the memory space will be wasted.
Therefore, We must know about the number of elements that are to be stored in the array beforehand.
Single dimensional Array
Single dimensional Array in Java
Single dimensional Array in C++
Single dimensional Array in C
Multidimensional Array
Two dimensional Array in C
Three dimensional Array
Three dimensional Array in Java
Three dimensional Array in C++
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…