Contents

 



 

1. What is an Array?

English:

An Array is a collection of elements of the same data type, stored in contiguous (continuous) memory locations.
It is used to store multiple values in a single variable instead of declaring separate variables for each value.

Hindi:

Array एक ऐसा variable होता है जिसमें हम एक ही प्रकार (data type) के कई values एक साथ लगातार memory locations में store कर सकते हैं।
इससे हमें बार-बार अलग-अलग variable बनाने की ज़रूरत नहीं पड़ती।

🔹 Example:

Without Array:

int a1 = 10;

int a2 = 20;

int a3 = 30;

With Array:

int a[3] = {10, 20, 30};
 

 2. Need of Array | Array की आवश्यकता क्यों?

English:

·        To store multiple values of the same type in one variable.

·        To access and process data easily using loops.

·        To reduce code length and complexity.

Hindi:

·        एक ही प्रकार के कई values को एक variable में store

करने के लिए।

· Data को आसानी से access और process करने के लिए।

· Program को छोटा और आसान बनाने के लिए।



3. Syntax of Array | Array का Syntax data_type array_name[size];

Hindi Explanation:

· data_type → किस प्रकार का डेटा है (int, float, char, etc.)

· array_name → Array का नाम

· size → कितने elements होंगे Array में
4. Types of Array | Array के प्रकार

Array मुख्यतः दो प्रकार के होते हैं:
(1) One Dimensional Array (1D Array) | एक आयामी एरे
English Explanation:

A 1D array is a simple list of elements of the same type, arranged in a single row.
Hindi Explanation:

1D Array एक सीधी रेखा (line) में एक जैसे type के elements को store करता है।
Example Program:





#include <stdio.h>

int main() {

int marks[5];

int i;



printf("Enter 5 marks:\n");

for(i = 0; i < 5; i++) {

printf("Enter mark %d: ", i+1);

scanf("%d", &marks[i]);

}



printf("\nYou entered:\n");

for(i = 0; i < 5; i++) {

printf("%d ", marks[i]);

}

return 0;

}

 


 

(2) Two Dimensional Array (2D Array) | द्वि-आयामी एरे

A 2D array is like a table (matrix) having rows and columns.

2D Array एक टेबल या मैट्रिक्स की तरह होता है जिसमें rows और columns होते हैं।

Syntax:

data_type array_name[rows][columns];{

{},

{}

}


#Example Program:

#include <stdio.h>

int main() {

int matrix[2][3]; // 2 rows and 3 columns

int i, j;

printf("Enter elements for 2x3 matrix:\n");

for(i = 0; i < 2; i++) {

for(j = 0; j < 3; j++) {

printf("Enter element [%d][%d]: ", i, j);

scanf("%d", &matrix[i][j]);

}

}

printf("\nMatrix is:\n");

for(i = 0; i < 2; i++) {

for(j = 0; j < 3; j++) {

printf("%d ", matrix[i][j]);

}

printf("\n");

}

return 0;

}



5. Initialization of Array | Array को प्रारंभ करना




Array को आप declaration के समय values दे सकते हैं।

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



OR (size automatically counted) int numbers[] = {10, 20, 30, 40, 50};


. Traversing an Array | Array के तत्वों को Access करना

You can use loops to access all elements of an array.

Hindi:

सभी elements को access करने के लिए loop (जैसे for loop) का प्रयोग किया जाता है।

 
for(i = 0; i < size; i++) {
printf("%d ", array[i]);
}

Important Points | महत्वपूर्ण बातें

No

Point

Explanation

1

Array index starts from 0

यानी पहला element array[0] होगा

2

All elements must be same data type

जैसे सभी int या सभी float

3

Size must be fixed

एक बार बनाए गए Array का size बदला नहीं जा सकता

4

Stored in contiguous memory

Memory में एक के बाद एक stored होते हैं