Skip to main content

Command Palette

Search for a command to run...

Introduction to Arrays

Updated
2 min read
Introduction to Arrays
V

🚀 Software Engineer at TechM | Ex Merkle | Design Enthusiast 🎨 | Graduate of KLS Gogte Institute of Technology 🎓 | Connector of People & Ideas 💡 | | React.js Aficionado | Eager Learner & Growth Advocate 🌱

What is an array?

An Array is a collection of the elements of Similar Data-Type stored one after another in the memory.

why do we use array ?

  • We can overcome the disadvantage of using many variables since variables are used to store more than one element of the same datatype.

Types of arrays.

  • 1D Array
  • 2D Array
  • 3D Array

Syntax to declare

Datatypes array_name[expression];

Quick Note.

ArraySize = No of elements * size of datatype

Array indexing starts from 0

A[3] (2).png

Different ways of array Initialization

    1. Initializing all the memory location

No of elements = Number of Elements

Int a[5] = { 10,20,30,40,50}
    1. Partial Array Initialization
      If the number of values initialized is less than the allocated memory then it is known as partial array initialization.
Int a[5] = { 10,20,30,40,70}
    1. Initialization without size

The number of elements has not been specified to values specified.

int a [ ] = {10,20,30};
    1. String Initialization Strings are defined as an array of characters with a null character in the end.
char str[50] = "GeeksforGeeks";

Program to Read Array and print it.

#include<stdio.h>


int main()
{
int i,arr[10], range;

printf("Enter the number of elements in array:\n");
scanf("%d", &range);

printf("Enter the array elements:\n");
    for(i=0; i<range; i++)
    {
    scanf("%d", &arr[i]);
    }

printf("aray elements are as follows:");
    for(i=0; i<range; i++)
    {
    printf("%d ", arr[i]);
    }

}
52 views

Python-Interview

Part 2 of 3

In this Series, we will learn python from scratch and work with different problem definition and approach to solve these problem.

Up next

Non-Repeated Characters in String

Finding Count of Characters that are not repeated in the string.