Array Data Structure in C, Types of Array 1D, 2D and nD (Multidimensional Array) and Need of Array (C में Array Data Structure, Array के प्रकार (1D, 2D और nD) तथा Array की आवश्यकता)

An Array is a collection of elements of the same data type stored in contiguous memory locations. All elements are accessed using a common array name and an index (subscript). The index of an array starts from 0 and ends at size - 1. The address of the first element of an array is called the Base Address of the array. In C language, an array is an important data structure used to store and process multiple values using a single name.

Array एक ही Data Type के अनेक Elements का समूह होता है। इसके सभी Elements कंप्यूटर की Memory में क्रमागत (Contiguous) स्थानों पर संग्रहीत होते हैं। Array के सभी Elements को एक ही नाम से पहचाना जाता है तथा प्रत्येक Element का अपना Index होता है। Array का Index हमेशा 0 से शुरू होता है और अंतिम Index size - 1 होता है। Array के पहले Element का Address उसका Base Address कहलाता है। C भाषा में Array का उपयोग एक ही नाम के अंतर्गत अनेक Values को संग्रहीत करने और उन पर आसानी से कार्य करने के लिए किया जाता है।

Example of an Array

Consider an integer array containing five elements:

int list[5] = {10, 20, 30, 40, 50};

The array elements and their indexes are:

IndexElement
010
120
230
340
450

In the above example:

  • list is the name of the array.

  • 5 represents the size of the array.

  • list[0] represents the first element.

  • list[4] represents the last element.

  • The valid index range is from 0 to 4.

ऊपर दिए गए उदाहरण में list Array का नाम है तथा इसमें कुल पाँच Integer Elements रखे गए हैं। पहला Element list[0] और अंतिम Element list[4] द्वारा Access किया जाता है। ध्यान रखें कि Array का Size 5 होने पर उसका Index 0 से 4 तक होता है।

Types of Array (Array के प्रकार)

In C language, arrays are commonly classified according to their dimensions: 

C भाषा में Dimensions के आधार पर Array को मुख्य रूप से निम्न प्रकारों में समझा जाता है:

  1. One-Dimensional एकविमीय Array (1D Array)

  2. Two-Dimensional द्विविमीय Array (2D Array)

  3. Multidimensional बहुविमीय Array (3D, 4D, ... nD Array)

One-Dimensional Array (एकविमीय Array)

A One-Dimensional Array (1D Array) is a collection of similar data elements arranged in a single sequence. It uses only one subscript or index to access its elements. It is commonly used to store a list of values such as marks, roll numbers, ages, and prices.

One-Dimensional Array का उपयोग एक सूची (List) के रूप में Data Elements को संग्रहीत करने के लिए किया जाता है। इसमें Elements को एक ही क्रम में रखा जाता है तथा किसी Element को Access करने के लिए केवल एक Index का उपयोग किया जाता है। जैसे विद्यार्थियों के अंक, Roll Numbers, आयु और वस्तुओं की कीमत आदि।

Declaration of 1D Array (1D Array की घोषणा)

Syntax:

data_type array_name[size];

For declaring multiple arrays:

data_type array1[size], array2[size], array3[size];

Examples:

char name[20];
int list[100];
float marks[50];

Initialization of 1D Array (1D Array का प्रारंभिक मान निर्धारित करना)

Array initialization means assigning initial values to its elements at the time of declaration.

Array Initialization का अर्थ है Array की घोषणा करते समय उसके Elements को प्रारंभिक Values प्रदान करना।

Syntax:

data_type array_name[size] = {value1, value2, value3, ...};

Examples:

char name[20] = {'D', 'i', 'v', 'y', 'a', '\0'};
int list[5] = {101, 102, 103, 104, 117};
float marks[5] = {67.5, 48.2, 89.9, 56.3, 75.5};

Note: If the array size is not specified, the compiler determines it from the number of initialized elements.

int numbers[] = {10, 20, 30, 40};

Here, the compiler determines the array size as 4.

Example: Accessing 1D Array Elements

#include <stdio.h>
int main()
{
int list[5] = {10, 20, 30, 40, 50};
int i;
for (i = 0; i < 5; i++)
{
printf("%d ", list[i]);
}
return 0;
}

Output:

10 20 30 40 50

इस उदाहरण में list[5] नाम का Integer Array बनाया गया है। इसमें पाँच Elements हैं। for Loop की सहायता से Index 0 से 4 तक प्रत्येक Element को Access करके Display किया गया है।

Two-Dimensional Array (द्विविमीय Array)

A Two-Dimensional Array (2D Array) is an array that uses two subscripts to access its elements. It is used to store data in tabular form, consisting of rows and columns. It is commonly used for storing matrices, tables, and other structured information.

Two-Dimensional Array का उपयोग Data को Rows और Columns के रूप में संग्रहीत करने के लिए किया जाता है। यह देखने में एक Table की तरह होता है। इसका उपयोग Matrix, विद्यार्थियों के विषयवार अंक, सारणी तथा अन्य व्यवस्थित जानकारियों को संग्रहीत करने के लिए किया जाता है। इसमें किसी Element को Access करने के लिए दो Index का उपयोग किया जाता है।

Declaration of 2D Array (2D Array की घोषणा)

Syntax:

data_type array_name[row_size][column_size];

Example:

int mat[3][3];

Here:

  • 3 represents the number of rows.

  • 3 represents the number of columns.

  • Total number of elements = 3 × 3 = 9.

For a 2D array A[m][n]:

  • Row index ranges from 0 to m - 1.

  • Column index ranges from 0 to n - 1.

  • Total elements = m × n.

Initialization of 2D Array (2D Array का प्रारंभिक मान निर्धारित करना)

Syntax:

data_type array_name[rows][columns] = {
{values of first row},
{values of second row}
};

Examples:

int mat[3][3] = {1, 0, 1, 2, 1, 2, 3, 3, 3};

Another way to initialize a 2D array is:

int mat[3][3] = {
{1, 0, 1},
{2, 1, 2},
{3, 3, 3}
};

Both declarations initialize the same matrix.

Example of 2D Array

Consider the following matrix:

int mat[3][3] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};

<AsyncImage query="two dimensional array 3 by 3 matrix row column indexes 0 1 2 educational C programming diagram" aspectRatio="16:9" width="100%" fit="contain"/>

The elements can be accessed using two indexes:

  • mat[0][0] = 1

  • mat[0][1] = 2

  • mat[1][1] = 5

  • mat[2][2] = 9

ऊपर दिए गए Matrix में पहला Index Row को तथा दूसरा Index Column को दर्शाता है। उदाहरण के लिए, mat[1][2] का अर्थ दूसरी Row और तीसरे Column का Element है, जिसका मान 6 है। ध्यान दें कि Index की गणना 0 से शुरू होती है।

Example: Displaying a 2D Array

#include <stdio.h>
int main()
{
int mat[3][3] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
int i, j;
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
printf("%d\t", mat[i][j]);
}
printf("\n");
}
return 0;
}

Output:

1 2 3
4 5 6
7 8 9

Multidimensional Array (बहुविमीय Array)

An array that uses more than two subscripts is called a Multidimensional Array. In C language, we can declare 3D, 4D, and higher-dimensional arrays. The number of subscripts used in the declaration represents the number of dimensions.

जिस Array में दो से अधिक Dimensions होते हैं, उसे Multidimensional Array कहा जाता है। C भाषा में हम 3D, 4D तथा आवश्यकता के अनुसार अधिक Dimensions वाले Arrays भी बना सकते हैं। Array की घोषणा में जितने Subscripts का उपयोग किया जाता है, वही उसकी Dimensions की संख्या बताते हैं।

General Syntax

data_type array_name[D1][D2][D3]...[Dn];

Here, D1, D2, D3 ... Dn represent the sizes of different dimensions.

Types of Multidimensional Array

A. Three-Dimensional Array (3D Array)

A 3D array uses three subscripts and can be considered a collection of 2D arrays.

3D Array में तीन Subscripts का उपयोग किया जाता है। इसे कई 2D Arrays के समूह के रूप में समझा जा सकता है।

Syntax:

data_type array_name[x][y][z];

Example:

int data[2][3][4];

Here, the array contains:

2 × 3 × 4 = 24 elements

B. Four-Dimensional Array (4D Array)

A 4D array uses four subscripts to access its elements.

4D Array में किसी Element को Access करने के लिए चार Subscripts का उपयोग किया जाता है।

Example:

int data[2][3][4][5];

C. Higher-Dimensional Array (nD Array)

C language also supports arrays with more than four dimensions, subject to compiler and implementation limits.

C भाषा में चार से अधिक Dimensions वाले Arrays भी बनाए जा सकते हैं। इनका उपयोग विशेष प्रकार की जटिल समस्याओं में किया जाता है।

Example:

int data[2][3][4][5][6];

Difference Between 1D, 2D and Multidimensional Arrays

1D, 2D और Multidimensional Array में अंतर

Feature1D Array2D ArrayMultidimensional Array
SubscriptsOneTwoMore than two
StructureLinear listRows and columnsMultiple dimensions
Examplea[5]a[3][3]a[2][3][4]
Accessa[i]a[i][j]a[i][j][k]
UsesLists, marksTables, matricesComplex structured data

1D Array में Data एक सूची के रूप में रखा जाता है, 2D Array में Data Rows और Columns के रूप में रखा जाता है, जबकि Multidimensional Array में Data को दो से अधिक Dimensions में व्यवस्थित किया जाता है। इन सभी में मुख्य अंतर Subscripts की संख्या और Data के संगठन का होता है।

Important Characteristics of Array (Array की प्रमुख विशेषताएँ)

  1. Same Data Type: An array stores elements of the same declared data type.

  2. Contiguous Memory: Array elements are stored in contiguous memory locations.

  3. Zero-Based Indexing: The first element is accessed using index 0.

  4. Fixed Size: The size of an ordinary array cannot be changed after its creation.

  5. Direct Access: Elements can be accessed directly using their indexes.

  6. Base Address: The array name, in most expressions, is converted to a pointer to its first element.

Array की सभी Values एक ही Data Type की होती हैं। इसके Elements क्रमागत Memory Locations में रखे जाते हैं और Index की शुरुआत 0 से होती है। सामान्य Array का Size उसकी घोषणा के समय निर्धारित किया जाता है। Index की सहायता से किसी भी Element को सीधे Access किया जा सकता है। C भाषा में अधिकांश Expressions में Array का नाम उसके पहले Element के Pointer में परिवर्तित हो जाता है।

Need of Array (Array की आवश्यकता)

Suppose we want to store marks of five students. Without using an array, we need to declare five different variables:

int marks1, marks2, marks3, marks4, marks5;

If we want to store marks of 100 students, declaring 100 separate variables becomes difficult. It also makes program management and processing complicated.

Using an array, we can store all these values under a single name:

int marks[100];

An array provides the following advantages:

  1. Multiple Values: It stores multiple values of the same data type using a single name.

  2. Easy Access: Elements can be accessed directly using their indexes.

  3. Contiguous Memory: Array elements are stored in contiguous memory locations.

  4. Easy Processing: Loops can be used to process all array elements efficiently.

  5. Reduced Complexity: It avoids declaring and managing many individual variables.

  6. Useful in Programming: Arrays are widely used in searching, sorting, matrix operations, and many other programming applications.

यदि हमें 100 विद्यार्थियों के अंक संग्रहीत करने हों, तो 100 अलग-अलग Variables बनाना कठिन होगा। इसके स्थान पर हम int marks[100]; लिखकर सभी विद्यार्थियों के अंक एक ही Array में रख सकते हैं। इससे Program छोटा और व्यवस्थित बनता है। Array के Elements को Index की सहायता से आसानी से Access किया जा सकता है तथा Loop द्वारा सभी Elements पर एक साथ Processing भी की जा सकती है।

Applications of Array (Array के उपयोग)

Arrays are widely used in programming for:

  • Storing marks, roll numbers, and student records.

  • Performing searching and sorting operations.

  • Matrix addition, subtraction, and multiplication.

  • Implementing stacks and queues.

  • Storing tables and numerical data.

  • Image processing and scientific calculations.

Programming में Array का उपयोग विद्यार्थियों के अंक और Roll Numbers रखने, Searching एवं Sorting करने, Matrix Operations करने, Stack और Queue जैसी Data Structures बनाने तथा Image Processing और Scientific Calculations में किया जाता है।

An array is one of the fundamental data structures in C programming. It allows programmers to store multiple values of the same data type under a single name and access them through indexes. Understanding 1D, 2D, and multidimensional arrays is essential for learning data structures and solving programming problems.

Array, C Programming की एक महत्वपूर्ण Fundamental Data Structure है। इसकी सहायता से एक ही Data Type की अनेक Values को एक नाम के अंतर्गत संग्रहीत किया जा सकता है। 1D, 2D तथा Multidimensional Arrays की समझ आगे Data Structures और Programming Problems को सीखने के लिए बहुत आवश्यक है।

Comments

Popular posts from this blog

C Language Topics in Hindi and English

Complete C Programming Syllabus | Advanced C Roadmap for Students

Top High-Paying Tech Skills to Learn in 2025