Defining and Processing Arrays

Introduction

Programming में जब हमें एक ही प्रकार (same data type) के बहुत सारे values को store करना होता है, तो हर value के लिए अलग-अलग variable बनाना practical नहीं होता।

उदाहरण के लिए:

  • 50 students के marks store करना
  • 100 numbers को process करना

अगर हम हर value के लिए अलग variable बनाएँ (marks1, marks2, …), तो program बहुत लंबा और difficult हो जाएगा।

इसी problem को solve करने के लिए C language में Arrays का concept दिया गया है।

Array एक ऐसा structure है जिसमें:

  • same type के multiple values store होते हैं
  • values continuous memory locations में stored होते हैं
  • हर value को index (position) से access किया जाता है

Arrays programming को:

  • simple बनाते हैं
  • organized बनाते हैं
  • efficient बनाते हैं

Definition

Array एक collection होता है जिसमें same data type के multiple elements continuous memory locations में store होते हैं और उन्हें index के माध्यम से access किया जाता है।

Defining an Array

Syntax

data_type array_name[size];

Example

int marks[5];

Explanation:

  • marks → array name
  • 5 → total elements
  • index → 0 से 4 तक

Initializing an Array

Example

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

Index mapping:

IndexValue
010
120
230
340
450

Processing Arrays

Processing का मतलब:

  • input लेना
  • output देना
  • calculation करना

Example 1: Array Input and Output

#include <stdio.h>
int main()
{
int arr[5], i;
for (i = 0; i < 5; i++)
{
scanf("%d", &arr[i]);
}
for (i = 0; i < 5; i++)
{
printf("%d ", arr[i]);
} return 0;
}

Explanation:

  • first loop → input लेता है
  • second loop → output देता है

Example 2: Sum of Array Elements

#include <stdio.h>
int main()
{
int arr[5] = {1, 2, 3, 4, 5};
int i, sum = 0;
for (i = 0; i < 5; i++)
{
sum = sum + arr[i];
} printf("Sum = %d", sum);
return 0;
}

Output:

Sum = 15

Explanation:

  • loop हर element को add करता है
  • final sum print होता है

Example 3: Maximum Element

#include <stdio.h>
int main()
{
int arr[5] = {10, 25, 5, 40, 15};
int i, max = arr[0];
for (i = 1; i < 5; i++)
{
if (arr[i] > max)
{
max = arr[i];
}
} printf("Max = %d", max);
return 0;
}

Output:

Max = 40

Explanation:

  • हर element compare हुआ
  • largest value store हो गई

Example 4: Even Numbers Print

#include <stdio.h>
int main()
{
int arr[5] = {1, 2, 3, 4, 5};
int i;
for (i = 0; i < 5; i++)
{
if (arr[i] % 2 == 0)
{
printf("%d ", arr[i]);
}
} return 0;
}

Output:

2 4

Explanation:

  • केवल even numbers print हुए

Important Points

  • Array index हमेशा 0 से start होता है
  • सभी elements same data type के होते हैं
  • memory continuous होती है
  • loops array processing के लिए जरूरी हैं

Technical Understanding

Arrays का use इन situations में होता है:

  • marks list
  • data collection
  • searching और sorting
  • statistical calculations

Exam Points

  • Array = same type elements का collection
  • Index 0 से start होता है
  • Continuous memory allocation होता है
  • Loop array processing के लिए जरूरी है
  • Sum, max, even-odd programs बहुत important हैं

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top