Array

Array data type in programming languages

Array data type in programming languages

We will learn about Array data type in programming languages

Description

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)

Java Array

Declaration of Array

When we declare the array in the programming language, we need to consider in two factors:

  • Type of elements
  • Number of elements

Syntax

Data_type Array_Name[Array_size];

Example

int marks[30];

float student_height[40];

char alphabets[26];

 

Array data type in programming

Array declaration in the programming language
int marks[6];
Array

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.

 

Array Initiation in Programming language
Int marks[6]={45,76,56,87,43,67}
Int Array

 

float Height[6]={45,76,56,87,43,67}

float array

Ways of initialization of an Array

int marks[]={34,65,78,98,43,}

initialization of array

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

 

Advantages of Array

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

 

Disadvantages of Java Array

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.

 

Array types

Single dimensional Array

Single dimensional Array in Java

Single dimensional Array in C++

Single dimensional Array in C

 

Multidimensional Array

 Two dimensional Array in Java

Two dimensional Array in C++

Two dimensional Array in C

 

Three dimensional Array

Three dimensional Array in Java

Three dimensional Array in C++

Three dimensional Array in C

 

Single dimensional Array in Java language
Single dimension Array of C language
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago