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

Introduction to Django

A high-level Python web framework called Django makes it possible for programmers to create web applications rapidly and effectively. It adheres to the Model-View-Controller (MVC) architectural design pattern, placing emphasis on the division of duties and encouraging code reuse. Django offers a comprehensive collection of conventions, frameworks, and tools that speed up development and promote best practises.

Binary Tree

Binary Tree is a Non-Linear data structure which has atmost 2 child . A Binary tree is represented by a pointer to the topmost node (commonly known as the “root”) of the tree. If the tree is empty, then the value of the root is NULL. Each node of a Binary Tree contains the following parts:

1 year ago By Aniket Prajapati
For Laravel Setting UP CI/CD Pipeline using GitHub, CodeDeploy, S3 and EC2

Setting ci/cd pipeline for laravel application on aws using github actions then uploading to s3 and using codedeploy application gets installled on EC2 instance

1 year ago By Santosh Kshirsagar
Top 10 Web Frameworks of 2023 Top 10 Web Frameworks of 2023

As technology evolves and new trends arise, the landscape of web frameworks is continually shifting. This article will present the top 10 web frameworks to consider in 2023.

1 year ago By Mitali Gupta