Limited Period Offer : 20% Discount on online/offline courses, for more details call/whatsapp

Arrays Introduction

1 min read
1 year ago By Aniket Prajapati

ARRAYS

We know datatypes like int ,char ,float ,double ,etc . Arrays comes into the roll when multiple data has to be stored of same data type.

Introduction

(1). An array is a collection of items of same data type stored at contiguous memory locations. (2). As array stores data in continuous memory location the user can find the location of data easily eg:- we can think of an array as a flight of stairs where on each step is placed a value (let’s say one of your friends). Here, you can identify the location of any of your friends by simply knowing the count of the step they are on.

(Tip: Location of index depends upon the datatype.)

Is the array always of a fixed size?

In C language, the array has a fixed size meaning once the size is given to it, it cannot be changed i.e. you can’t shrink it nor can you expand it. The reason was that for expanding if we change the size we can’t be sure ( it’s not possible every time) that we get the next memory location to us for free. The shrinking will not work because the array, when declared, gets memory statically allocated, and thus compiler is the only one that can destroy it.

code to understand :

#include

using namespace std;

int main() { // initialize an integer array with three elements, all // of which are initially set to 0 int arr[3] = { 0, 0, 0 };

// set the first element to 1
arr[0] = 1;

// set the second element to 2
arr[1] = 2;

// set the third element to 3
arr[2] = 3;

// print the contents of the array to the console using
// a for loop
for (int i = 0; i < 3; i++) {
	cout << arr[i] << " ";
}

return 0;

}

Jun 12, 2023 21:40 Back to Articles

Other Articles

Prim's Algorithm

Prim's Algorithm is a graph algorithm and this algorithm works as it starts with a single node and then moves through several adjacent nodes form that node , in order to explore all of the connected edges along the way.

1 year ago By Aniket Prajapati
Level Order Traversal in Binary Tree

In a Binary Tree the level order traversal is used to traverse all the elements of binary tree by starting from root to traversing all nodes of one level before moving to other level.

1 year ago By Aniket Prajapati
linked list

A linked list is a linear data structure, in which the elements are not stored at contiguous memory locations. The elements in a linked list are linked using pointers . This elements can be accessed by pointer traversing.

1 year ago By Aniket Prajapati
What is CI/CD ? What is CI/CD ?

This article examines the meaning and significance of CI/CD in software development, emphasizing its role in improving the efficiency and reliability of software releases through automation and continuous integration and delivery.

1 year ago By Mitali Gupta