Representation of Array

The representation of an array can be defined by its declaration. A declaration means allocating memory for an array of a given size.

Representation of Array

Arrays can be declared in various ways in different languages. For better illustration, below are some language-specific array declarations.

C++




int arr[5]; // This array will store integer type element
char arr[10]; // This array will store char type element
float arr[20]; // This array will store float type element


C




int arr[5]; // This array will store integer type element
char arr[10]; // This array will store char type element
float arr[20]; // This array will store float type element


Java




/* Static Arrays are arrays that are declared before runtime
and are assigned values while writing the code.
*/
  
// The syntax of declaring a static array is:
<data type><variable name>[]
    = {<data1>, <data2>,…..<dataN> };
  
// Example:
int arr[] = { 2, 5, 6, 9, 7, 4, 3 };


Python3




# Python code
arr = [10, 20, 30# This array will store integer
arr2 = ['c', 'd', 'e'# This array will store characters
arr3 = [28.5, 36.5, 40.2# This array will store floating elements


C#




int[] arr = new int[5]; // This array will store integer
                        // type element


Javascript




// JS code
let arr=[10,20,30]; // This array will store integer
let arr2 = ['c', 'd', 'e'] // This array will store characters
let arr3 = [28.5, 36.5, 40.2] // This array will store floating elements


However, the above declaration is static or compile-time memory allocation, which means that the array element’s memory is allocated when a program is compiled. Here only a fixed size (i,e. the size that is mentioned in square brackets []) of memory will be allocated for storage, but don’t you think it will not be the same situation as we know the size of the array every time, there might be a case where we don’t know the size of the array. If we declare a larger size and store a lesser number of elements will result in a wastage of memory or either be a case where we declare a lesser size then we won’t get enough memory to store the rest of the elements. In such cases, static memory allocation is not preferred.

Array Notes for GATE Exam [2024]

Arrays are fundamental data structures in computer science, and mastering them is crucial for success in the GATE exam. This article aims to provide concise yet comprehensive notes on arrays, covering essential concepts and strategies to help you tackle array-related questions in the GATE 2024 exam.

Table of Content

  • Introduction to Arrays
  • Basic terminologies of the array
  • Representation of Array
  • Types of arrays
  • Finding Adress of an Element in Array
  • Calculating the address of any element In the 1-D array
  • Calculate the address of any element in the 2-D array
  • Calculate the address of any element in the 3-D Array
  • Previously Asked GATE Questions on Arrays

Similar Reads

Introduction to Arrays:

An array is a collection of items of the same variable type that are stored at contiguous memory locations. It’s one of the most popular and simple data structures and is often used to implement other data structures. Each item in an array is indexed starting with 0....

Basic terminologies of the array:

Array Index: In an array, elements are identified by their indexes. Array index starts from 0. Array element: Elements are items stored in an array and can be accessed by their index. Array Length: The length of an array is determined by the number of elements it can contain....

Representation of Array:

The representation of an array can be defined by its declaration. A declaration means allocating memory for an array of a given size....

Types of arrays:

...

Finding Adress of an Element in Array

...

Calculating the address of any element In the 1-D array:

...

Calculate the address of any element in the 2-D array:

...

Calculate the address of any element in the 3-D Array:

...

Previously Asked GATE Questions on Arrays:

...