Sunday, August 31, 2025

lesson 3 Array (Hindi medium Q&A)

 

Array (ऐरे) – प्रश्नोत्तर 


Part A: Multiple Choice Questions (1 अंक प्रत्येक)

Q1. एक ऐरे (Array) किन प्रकार के मान (values) को संग्रहीत करता है?
(a) अलग–अलग डेटा टाइप
(b) समान डेटा टाइप
(c) दोनों
(d) इनमें से कोई नहीं
उत्तर: (b)

Q2. C भाषा में ऐरे का इंडेक्स (Index) किससे शुरू होता है?
(a) 1
(b) -1
(c) 0
(d) 2
उत्तर: (c)

Q3. निम्न में से कौन-सा 5 आकार के इन्टीजर ऐरे का सही घोषणा है?
(a) int marks(5);
(b) int marks[5];
(c) int[5] marks;
(d) marks int[5];
उत्तर: (b)

Q4. int num[10]; ऐरे में कितने एलिमेंट (तत्व) होंगे?
(a) 5
(b) 9
(c) 10
(d) 11
उत्तर: (c)

Q5. निम्न में से कौन-सा ऐरे को सही तरीके से इनिशियलाइज़ (Initialize) करता है?
(a) int a[] = {10, 20, 30};
(b) int a[3] = {10, 20, 30};
(c) int a[5] = {10, 20, 30};
(d) उपरोक्त सभी
उत्तर: (d)

Q6. marks[0] किसको दर्शाता है?
(a) आखिरी तत्व
(b) पहला तत्व
(c) बीच का तत्व
(d) इनमें से कोई नहीं
उत्तर: (b)

Q7. दो-आयामी (2D) ऐरे का सही घोषणा कौन-सा है?
(a) int a[2][3];
(b) int a(2,3);
(c) int a[2,3];
(d) int[2][3]a;
उत्तर: (a)

Q8. int a[4][5]; ऐरे में कुल कितने तत्व होंगे?
(a) 9
(b) 10
(c) 20
(d) 25
उत्तर: (c)

Q9. 2D ऐरे के तत्वों को एक्सेस करने के लिए क्या उपयोग होता है?
(a) एक इंडेक्स
(b) दो इंडेक्स
(c) केवल पॉइंटर
(d) इनमें से कोई नहीं
उत्तर: (b)

Q10. किस लूप का उपयोग ऐरे के सभी तत्वों को एक्सेस करने के लिए सबसे उपयुक्त है?
(a) while loop
(b) for loop
(c) do-while loop
(d) switch
उत्तर: (b)

Q11. ऐरे कहाँ संग्रहीत होता है?
(a) रैंडम मेमोरी
(b) लगातार (Contiguous) मेमोरी लोकेशन्स
(c) अलग-अलग ब्लॉक्स
(d) इनमें से कोई नहीं
उत्तर: (b)

Q12. int a[3][4]; में कुल कितने तत्व होंगे?
(a) 7
(b) 10
(c) 12
(d) 15
उत्तर: (c)

Q13. निम्न में से कौन ऐरे का लाभ नहीं है?
(a) इंडेक्स द्वारा आसान एक्सेस
(b) मेमोरी का कुशल उपयोग
(c) अलग-अलग डेटा टाइप स्टोर कर सकता है
(d) कोड को सरल बनाता है
उत्तर: (c)

Q14. ऐरे का आकार (Size) कब तय होता है?
(a) रनटाइम पर बदला जा सकता है
(b) घोषणा (Declaration) के समय
(c) यह अनंत हो सकता है
(d) इनमें से कोई नहीं
उत्तर: (b)

Q15. ऐरे का उपयोग किसमें किया जा सकता है?
(a) छात्रों के अंक संग्रहीत करने में
(b) टाइम-टेबल संग्रहीत करने में
(c) इमेज प्रोसेसिंग
(d) उपरोक्त सभी
उत्तर: (d)

Q16. C भाषा में ऐरे इंडेक्सिंग के लिए कौन-सा चिन्ह प्रयोग होता है?
(a) ( )
(b) { }
(c) [ ]
(d) < >
उत्तर: (c)

Q17. इनमें से कौन-सा 1D ऐरे है?
(a) int a[10];
(b) int a[5][5];
(c) int a[2][3][4];
(d) इनमें से कोई नहीं
उत्तर: (a)

Q18. यदि int arr[5] = {1, 2, 3}; तो arr[3] = ?
(a) 3
(b) 0
(c) 2
(d) Garbage value
उत्तर: (b)

Q19. int a[2][3] = {{1,2,3}, {4,5,6}}; में a[1][2] का मान क्या है?
(a) 3
(b) 4
(c) 5
(d) 6
उत्तर: (d)

Q20. 1D और 2D ऐरे में मुख्य अंतर क्या है?
(a) 1D में कई पंक्तियाँ होती हैं, 2D में केवल एक पंक्ति
(b) 1D रैखिक (linear) है, 2D सारणीबद्ध (rows और columns) है
(c) 1D में दो इंडेक्स, 2D में एक इंडेक्स होता है
(d) इनमें से कोई नहीं
उत्तर: (b)


Part B: बहुत छोटे प्रश्न (1 अंक प्रत्येक)

Q1. ऐरे की परिभाषा बताइए।
Ans:- ऐरे समान डेटा टाइप के तत्वों का संग्रह है, जो लगातार मेमोरी लोकेशन में संग्रहीत होते हैं और इंडेक्स द्वारा एक्सेस किए जाते हैं।

Q2. ऐरे का पहला इंडेक्स क्या होता है?
Ans:- 0

Q3. एक-आयामी ऐरे को घोषित करने का सिंटैक्स लिखिए।
Ans:- data_type array_name[size];
उदाहरण: int marks[5];

Q4. int arr[5]; में कितने तत्व होंगे?
Ans:- 5 तत्व

Q5. ऐरे इनिशियलाइज़ेशन का एक उदाहरण दीजिए।
Ans:- int num[3] = {10, 20, 30};

Q6. C भाषा में printf() के लिए कौन-सी हेडर फाइल आवश्यक है?
Ans:- <stdio.h>

Q7. दो-आयामी ऐरे क्या है?
Ans:- दो-आयामी ऐरे ऐरे का ऐरे है जिसमें तत्व पंक्तियों और स्तंभों में संग्रहीत होते हैं।

Q8. 1D ऐरे का एक वास्तविक जीवन उपयोग बताइए।
Ans:- छात्रों के अंक संग्रहीत करना।

Q9. 2D ऐरे का एक वास्तविक जीवन उपयोग बताइए।
Ans:- टाइम-टेबल को पंक्तियों और स्तंभों में दर्शाना।

Q10. ऐरे के Declaration और Initialization में अंतर बताइए।
Ans:-

  • Declaration: केवल ऐरे को घोषित करना (जैसे, int arr[5];).

  • Initialization: घोषणा के समय मान देना (जैसे, int arr[5] = {10,20,30,40,50};).

Part C: छोटे उत्तर वाले प्रश्न (2–3 अंक प्रत्येक)

Q1. ऐरे और साधारण वेरिएबल (Variable) में अंतर बताइए।
Ans:-

  • वेरिएबल केवल एक मान (value) संग्रहीत करता है।

  • ऐरे समान प्रकार (same type) के कई मान संग्रहीत कर सकता है।

  • वेरिएबल को बार–बार घोषित करना पड़ता है, पर ऐरे में एक ही नाम से कई मान रखे जा सकते हैं।


Q2. ऐरे के फायदे लिखिए।
Ans:-

  1. समान डेटा टाइप के कई मान आसानी से संग्रहीत कर सकते हैं।

  2. सभी मान लगातार (contiguous) मेमोरी लोकेशन में रहते हैं।

  3. इंडेक्स द्वारा किसी भी तत्व को आसानी से एक्सेस किया जा सकता है।

  4. प्रोग्राम को छोटा और सरल बनाता है।


Q3. 1D ऐरे और 2D ऐरे में अंतर बताइए।
Ans:-

  • 1D ऐरे: यह रैखिक (linear) होता है और केवल एक इंडेक्स से एक्सेस किया जाता है।

  • 2D ऐरे: यह सारणीबद्ध (tabular form) होता है और दो इंडेक्स (row और column) से एक्सेस किया जाता है।


Q4. int marks[5] = {10, 20, 30}; लिखने पर शेष तत्वों का मान क्या होगा?
Ans:- शेष दो तत्व (marks[3] और marks[4]) का मान 0 होगा।


Q5. निम्न प्रोग्राम का आउटपुट लिखिए –

#include <stdio.h> int main() { int arr[5] = {2,4,6,8,10}; printf("%d", arr[3]); return 0; }

Ans:- आउटपुट होगा → 8


Q6. दो-आयामी ऐरे int a[3][4]; में कुल कितने तत्व होंगे?
Ans:- 3 × 4 = 12 तत्व।


Q7. ऐरे का उपयोग करके छात्रों के 5 अंकों का औसत निकालने का एक छोटा प्रोग्राम लिखिए।
Ans:-

#include <stdio.h> int main() { int marks[5] = {80, 70, 90, 60, 85}; int i, sum = 0; float avg; for(i = 0; i < 5; i++) { sum += marks[i]; } avg = sum / 5.0; printf("Average = %.2f", avg); return 0; }

Q8. यदि int arr[2][2] = {{1,2},{3,4}}; तो arr[1][0] का मान क्या है?
Ans:- 3


Part D: लम्बे उत्तर वाले प्रश्न (4–5 अंक प्रत्येक)

Q1. ऐरे की परिभाषा दीजिए और इसका सिंटैक्स तथा उदाहरण लिखिए।
Ans:-

  • परिभाषा: ऐरे समान डेटा टाइप के तत्वों का एक संग्रह है जो लगातार मेमोरी लोकेशन में संग्रहीत रहते हैं और इंडेक्स द्वारा एक्सेस किए जाते हैं।

  • सिंटैक्स:
    data_type array_name[size];

  • उदाहरण:
    int marks[5] = {10, 20, 30, 40, 50};


Q2. ऐरे के प्रकार (Types of Array) समझाइए।
Ans:-

  1. एक-आयामी (1D) ऐरे:

    • रैखिक रूप से तत्व संग्रहीत करता है।

    • Ex: int a[5];

  2. दो-आयामी (2D) ऐरे:

    • सारणी (table) रूप में तत्व संग्रहीत करता है।

    • Ex: int a[3][4];

  3. बहु-आयामी (Multidimensional) ऐरे:

    • 2D से अधिक dimensions वाले ऐरे।

    • Ex: int a[2][3][4];


Q3. 1D ऐरे और 2D ऐरे के लिए एक-एक प्रोग्राम लिखिए।

Ans:-1D ऐरे (तत्वों को प्रिंट करना)

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

2D ऐरे (तत्वों को प्रिंट करना)

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

Q4. ऐरे और पॉइंटर (Pointer) में सम्बन्ध बताइए।
Ans:-

  • ऐरे का नाम उसके पहले तत्व के पते (address) को दर्शाता है।

  • arr[0] का पता और &arr[0] समान होता है।

  • पॉइंटर का उपयोग ऐरे के सभी तत्वों को एक्सेस करने के लिए किया जा सकता है।


Q5. निम्न प्रोग्राम का आउटपुट बताइए –

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

Ans:- आउटपुट होगा → Sum = 75

Lesson 3 (Q&A)

 

Array 


Part A: Multiple Choice Questions (1 Mark Each)

  1. An array stores values of:
    (a) Different data types
    (b) Same data type
    (c) Both same and different data type
    (d) None of these
    Answer: (b)

  2. Array index in C always starts from:
    (a) 1
    (b) -1
    (c) 0
    (d) 2
    Answer: (c)

  3. Which of the following is the correct declaration of an integer array of size 5?
    (a) int marks(5);
    (b) int marks[5];
    (c) int[5] marks;
    (d) marks int[5];
    Answer: (b)

  4. What is the size of an array int num[10];?
    (a) 5 elements
    (b) 9 elements
    (c) 10 elements
    (d) 11 elements
    Answer: (c)

  5. Which of the following initializes an array correctly?
    (a) int a[] = {10, 20, 30};
    (b) int a[3] = {10, 20, 30};
    (c) int a[5] = {10, 20, 30};
    (d) All of these
    Answer: (d)

  6. What does marks[0] represent?
    (a) Last element of array
    (b) First element of array
    (c) Middle element of array
    (d) None of these
    Answer: (b)

  7. Which of the following is a two-dimensional array declaration?
    (a) int a[2][3];
    (b) int a(2,3);
    (c) int a[2,3];
    (d) int[2][3]a;
    Answer: (a)

  8. A 2D array of int a[4][5]; has how many total elements?
    (a) 9
    (b) 10
    (c) 20
    (d) 25
    Answer: (c)

  9. Accessing elements in 2D array is done using:
    (a) Single index
    (b) Double index
    (c) Pointer only
    (d) None
    Answer: (b)

  10. Which loop is best suited for traversing all elements of an array?
    (a) while loop
    (b) for loop
    (c) do-while loop
    (d) switch
    Answer: (b)

  11. An array is stored in:
    (a) Random memory
    (b) Contiguous memory locations
    (c) Separate memory blocks
    (d) None of these
    Answer: (b)

  12. The number of elements in int a[3][4]; is:
    (a) 7
    (b) 10
    (c) 12
    (d) 15
    Answer: (c)

  13. Which of the following is NOT an advantage of arrays?
    (a) Easy access using index
    (b) Efficient memory usage
    (c) Can store values of different data types
    (d) Code simplification
    Answer: (c)

  14. Which statement is correct about array size?
    (a) Can be changed during runtime
    (b) Must be defined at declaration
    (c) Can be infinite
    (d) None
    Answer: (b)

  15. Which of the following is an application of arrays?
    (a) Storing student marks
    (b) Storing timetable
    (c) Image processing
    (d) All of these
    Answer: (d)

  16. In C, which symbol is used for array indexing?
    (a) ( )
    (b) { }
    (c) [ ]
    (d) < >
    Answer: (c)

  17. Which of these is a one-dimensional array?
    (a) int a[10];
    (b) int a[5][5];
    (c) int a[2][3][4];
    (d) None
    Answer: (a)

  18. If int arr[5] = {1, 2, 3}; then arr[3] = ?
    (a) 3
    (b) 0
    (c) 2
    (d) Garbage value
    Answer: (b)

  19. In int a[2][3] = {{1,2,3}, {4,5,6}}; what is value of a[1][2]?
    (a) 3
    (b) 4
    (c) 5
    (d) 6
    Answer: (d)

  20. What is the main difference between 1D and 2D arrays?
    (a) 1D has multiple rows, 2D has one row
    (b) 1D is linear, 2D is tabular (rows and columns)
    (c) 1D uses two indices, 2D uses one index
    (d) None
    Answer: (b)

Part B: Very Short Answer Questions (1 Mark Each)

Q1. Define an array.
Ans:- An array is a collection of elements of the same data type stored in contiguous memory locations and accessed using an index.

Q2. What is the starting index of an array?
Ans:- The starting index of an array is 0.

Q3. Write the syntax for declaring a one-dimensional array.
Ans:- data_type array_name[size];
Example: int marks[5];

Q4. How many elements are there in int arr[5]?
Ans:- There are 5 elements in arr[5].

Q5. Give one example of array initialization.
Ans:- int num[3] = {10, 20, 30};

Q6. Which header file is needed for printf() in C?
Ans:- The header file is <stdio.h>.

Q7. What is a two-dimensional array?
Ans:- A two-dimensional array is an array of arrays where elements are stored in rows and columns.

Q8. Write any one real-life use of 1D array.
Ans:- Storing marks of students in a class.

Q9. Write any one real-life use of 2D array.
Ans:- Representing a timetable in rows and columns.

Q10. Write the difference between declaration and initialization of an array.
Ans:-

  • Declaration: Defining the array with size (e.g., int arr[5];).

  • Initialization: Assigning values at the time of declaration (e.g., int arr[5] = {10, 20, 30, 40, 50};).


Part C: Short Answer Questions (2–3 Marks Each)

Q1. Write advantages of one-dimensional arrays.
Ans:-

  1. Efficient storage of multiple values of the same type.

  2. Easy access to elements using index.

  3. Simplifies code with loops.

  4. Stored in contiguous memory locations.

Q2. Write advantages of two-dimensional arrays.
Ans:-

  1. Stores tabular data in rows and columns.

  2. Simplifies code for handling matrices and tables.

  3. Efficient memory usage.

  4. Useful in complex applications like games, images, and schedules.

Q3. Write a C program to input and display 5 numbers using an array.
Ans:-

#include <stdio.h> int main() { int num[5], i; printf("Enter 5 numbers:\n"); for(i = 0; i < 5; i++) { scanf("%d", &num[i]); } printf("You entered:\n"); for(i = 0; i < 5; i++) { printf("%d ", num[i]); } return 0; }

Q4. Differentiate between one-dimensional and two-dimensional arrays.
Ans:-

  • 1D Array: Stores elements in a single row. Example: int marks[5];

  • 2D Array: Stores elements in rows and columns. Example: int marks[2][3];

Q5. What happens if we do not initialize all elements of an array?
Ans:- The remaining elements are automatically initialized to 0.


Part D: Long Answer Questions (5 Marks Each)

Q1. Explain one-dimensional arrays with syntax, example, advantages, and uses.
Ans:-

  • Definition: A linear collection of elements stored in contiguous memory.

  • Syntax: data_type array_name[size];

  • Example: int marks[5] = {90, 80, 70, 60, 50};

  • Advantages: Efficient storage, easy access, loop-based processing.

  • Uses: Storing marks, daily temperatures, roll numbers, sales data.


Q2. Explain two-dimensional arrays with syntax, example, advantages, and uses.
Ans:-

  • Definition: An array of arrays where data is arranged in rows and columns.

  • Syntax: data_type array_name[rows][columns];

  • Example:

int marks[2][3] = { {90, 85, 76}, {88, 95, 80} };
  • Advantages: Tabular storage, efficient for matrices, easy access.

  • Uses: Storing tables, timetables, games (chess), image data, mathematical matrices.


Q3. Write a C program to store marks of 5 students in an array and print them.
Ans:-

#include <stdio.h> int main() { int marks[5], i; printf("Enter marks of 5 students:\n"); for(i = 0; i < 5; i++) { scanf("%d", &marks[i]); } printf("Marks of students are:\n"); for(i = 0; i < 5; i++) { printf("%d ", marks[i]); } return 0; }

Q4. Write a program to store and print elements of a 2×3 matrix using a 2D array.
Ans:-

#include <stdio.h> int main() { int a[2][3], i, j; printf("Enter elements of 2x3 matrix:\n"); for(i = 0; i < 2; i++) { for(j = 0; j < 3; j++) { scanf("%d", &a[i][j]); } } printf("Matrix is:\n"); for(i = 0; i < 2; i++) { for(j = 0; j < 3; j++) { printf("%d ", a[i][j]); } printf("\n"); } return 0; }

Q5. Compare one-dimensional and two-dimensional arrays with examples.
Ans:-

  • One-Dimensional Array:

    • Stores data in a single row.

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

    • Use: Storing marks, roll numbers, daily temperatures.

  • Two-Dimensional Array:

    • Stores data in rows and columns.

    • Example:

    int a[2][3] = { {1, 2, 3}, {4, 5, 6} };
    • Use: Timetables, matrices, games, images.

Lesson 3 Array (Hindi Medium)

 

ऐरे (Array)

1. ऐरे की परिभाषा

ऐरे एक डेटा संरचना (data structure) है जिसमें एक ही प्रकार (data type) के कई मान (values) को एक ही नाम से संग्रहीत किया जा सकता है।

प्रत्येक मान (value) को इंडेक्स (index) के द्वारा एक्सेस किया जाता है।
इंडेक्स हमेशा 0 से शुरू होता है।


ऐरे की घोषणा (Declaration of Array)

सामान्य स्वरूप (General Syntax):

data_type array_name[size];

उदाहरण (Examples):

int marks[5]; // 5 पूर्णांक (integers) संग्रहीत करने के लिए ऐरे float avg[10]; // 10 दशमलव मान (floating-point numbers) संग्रहीत करने के लिए char name[20]; // 20 अक्षर (characters) संग्रहीत करने के लिए

ऐरे का प्रारंभिककरण (Initialization of Array)

जब किसी ऐरे को घोषणा (declaration) के समय ही मान दिए जाते हैं तो इसे Initialization कहते हैं।

int num[5] = {10, 20, 30, 40, 50}; // num[0]=10, num[1]=20, … num[4]=50

अगर आकार (size) निर्दिष्ट नहीं किया गया है, तो कम्पाइलर स्वयं इसे गिन लेता है:

int num[] = {5, 10, 15}; // आकार (size) अपने आप 3 हो जाएगा

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

(A) एक-आयामी ऐरे (One-Dimensional Array)

एक-आयामी ऐरे एक रेखीय संग्रह (linear collection) है जिसमें समान प्रकार के तत्व (elements) निरंतर (contiguous) स्मृति स्थानों में संग्रहीत होते हैं।
इसे सिंगल-डायमेंशनल ऐरे या लीनियर ऐरे भी कहते हैं।

घोषणा (Declaration)

data_type array_name[size];

उदाहरण:

int marks[5]; // 5 तत्वों वाला पूर्णांक ऐरे

प्रारंभिककरण (Initialization)

int marks[5] = {90, 85, 76, 88, 95}; int marks[5] = {90, 85}; // शेष मान 0 हो जाएंगे int marks[] = {90, 85, 76, 88, 95}; // आकार अपने आप 5 होगा

तत्वों का उपयोग (Accessing Elements)

marks[0] = 90; // पहला तत्व marks[1] = 85; // दूसरा तत्व

सभी तत्व प्रिंट करने का उदाहरण:

for(int i = 0; i < 5; i++) { printf("%d ", marks[i]); }

एक-आयामी ऐरे के फायदे (Advantages)

  • प्रभावी संग्रहण – एक ही नाम से समान प्रकार के कई मानों का संग्रह।

  • आसान पहुँच – किसी भी तत्व तक इंडेक्स से सीधा पहुँचा जा सकता है।

  • कोड को सरल बनाना – लूप्स द्वारा सभी तत्वों को आसानी से प्रोसेस किया जा सकता है।

  • स्मृति प्रबंधन – तत्व लगातार (contiguous) स्मृति में संग्रहित होते हैं।

  • पुन: प्रयोग – फंक्शनों में ऐरे का प्रयोग करके कोड को मॉड्यूलर बनाया जा सकता है।

एक-आयामी ऐरे के उपयोग (Uses)

  • छात्रों के अंक (marks) या स्कोर संग्रहीत करना।

  • दैनिक आंकड़े जैसे तापमान, मासिक बिक्री आदि।

  • डेटा प्रोसेसिंग (searching, sorting, modifying)।

  • गणितीय क्रियाएँ (जैसे वेक्टर और सीक्वेंस)।

  • वास्तविक जीवन अनुप्रयोग (दुकान के दाम, रोल नंबर, कर्मचारी ID)।


(B) द्वि-आयामी ऐरे (Two-Dimensional Array)

द्वि-आयामी ऐरे एक ऐसा ऐरे है जिसमें पंक्तियों (rows) और स्तंभों (columns) में तत्व संग्रहीत होते हैं।
इसे मैट्रिक्स (matrix) या टेबल (table) भी कहते हैं।

उदाहरण (Example)

int a[2][3] = { {1, 2, 3}, {4, 5, 6} }; // a[0][0] = 1 // a[0][1] = 2 // a[1][2] = 6

घोषणा (Declaration)

data_type array_name[rows][columns];

उदाहरण:

int marks[3][4]; // 3 पंक्तियाँ और 4 स्तंभ (कुल 12 तत्व)

प्रारंभिककरण (Initialization)

int marks[2][3] = { {90, 85, 76}, {88, 95, 80} }; int marks[2][3] = {90, 85, 76, 88, 95, 80};

तत्वों का उपयोग (Accessing Elements)

marks[0][0] = 90; // पहली पंक्ति, पहला स्तंभ marks[1][2] = 80; // दूसरी पंक्ति, तीसरा स्तंभ

सभी तत्व प्रिंट करने का उदाहरण:

for(int i = 0; i < 2; i++) { for(int j = 0; j < 3; j++) { printf("%d ", marks[i][j]); } printf("\n"); }

द्वि-आयामी ऐरे के फायदे (Advantages)

  • सारणीबद्ध प्रस्तुति (Tabular Representation) – डेटा को पंक्तियों और स्तंभों में व्यवस्थित करता है।

  • आसान पहुँच – पंक्ति और स्तंभ इंडेक्स द्वारा सीधे तत्व तक पहुँचना।

  • कोड सरल बनाना – अलग-अलग 1D ऐरे की जगह एक 2D ऐरे पर्याप्त।

  • स्मृति का प्रभावी उपयोग – लगातार स्मृति में संग्रहण।

  • जटिल अनुप्रयोगों में उपयोगी – मैट्रिक्स, ग्राफ़, तालिका डेटा इत्यादि।

द्वि-आयामी ऐरे के उपयोग (Uses)

  • गणित (Matrices) – जोड़, घटाना, गुणा आदि।

  • सारणीबद्ध डेटा संग्रह – जैसे छात्रों के विभिन्न विषयों के अंक।

  • समय सारणी (Timetables) – विद्यालय/कॉलेज टाइमटेबल।

  • गेम डेवलपमेंट – शतरंज, सुडोकू, टिक-टैक-टो।

  • इमेज प्रोसेसिंग – इमेज को पिक्सल की 2D ऐरे के रूप में संग्रहीत किया जाता है।

  • नक्शे और ग्रिड – नेविगेशन, पाथ फाइंडिंग और वैज्ञानिक डाटा में प्रयोग।

Lesson 3

                                              Array

1. Definition of Array

An array is a data structure that stores a collection of values of the same data type under one name. Each value in an array is accessed by an index. Index always starts from 0.

Declaration of Array

General Syntax:

data_type array_name[size];

Examples:


int marks[5];     // An array to store 5 integers
float avg[10];    // An array to store 10 floating-point numbers
char name[20];    // An array to store 20 characters

Initialization of Array

When values are given to an array at the time of declaration, it is called initialization.


int num[5] = {10, 20, 30, 40, 50};
// num[0]=10, num[1]=20, … num[4]=50

If size is not specified, the compiler automatically calculates it:


int num[] = {5, 10, 15};
// Size becomes 3 automatically

Types of Array

(A) One-Dimensional Array

A one-dimensional array is a linear collection of elements of the same data type stored in contiguous memory locations. It is also called a single-dimensional array or a linear array.

Declaration of One-Dimensional Array

data_type array_name[size];

Example:


int marks[5]; // Creates an integer array with 5 elements

Initialization of One-Dimensional Array


int marks[5] = {90, 85, 76, 88, 95};
int marks[5] = {90, 85};     // remaining elements become 0
int marks[] = {90, 85, 76, 88, 95};  // size auto becomes 5

Accessing Elements


marks[0] = 90;  // first element
marks[1] = 85;  // second element

Example (printing all elements):


for(int i = 0; i < 5; i++) {
    printf("%d ", marks[i]);
}

Advantages of One-Dimensional Array

  • Efficient Storage – Stores multiple values of the same type under one name.
  • Easy Access – Any element can be accessed using its index.
  • Code Simplification – Loops can process all elements easily.
  • Memory Management – Stored in contiguous memory locations.
  • Reusability – Arrays can be used with functions for modularity.

Uses of One-Dimensional Array

  • Storing student marks or scores.
  • Storing daily data like temperatures, monthly sales, etc.
  • Data processing (searching, sorting, modifying).
  • Mathematical operations (vectors, sequences).
  • Real-life applications (shop prices, roll numbers, employee IDs).

(B) Two-Dimensional Array

A two-dimensional array is an array of arrays where elements are arranged in rows and columns. It is also called a matrix array or table.

Example:


int a[2][3] = {
    {1, 2, 3},
    {4, 5, 6}
};

// a[0][0] = 1
// a[0][1] = 2
// a[1][2] = 6

Declaration of Two-Dimensional Array

data_type array_name[rows][columns];

Example:


int marks[3][4]; // 3 rows and 4 columns (12 elements)

Initialization of Two-Dimensional Array


int marks[2][3] = {
    {90, 85, 76},
    {88, 95, 80}
};

int marks[2][3] = {90, 85, 76, 88, 95, 80};

Accessing Elements


marks[0][0] = 90;   // First row, first column
marks[1][2] = 80;   // Second row, third column

Example (printing all elements):


for(int i = 0; i < 2; i++) {
    for(int j = 0; j < 3; j++) {
        printf("%d ", marks[i][j]);
    }
    printf("\n");
}

Advantages of Two-Dimensional Array

  • Tabular Data Representation – Stores data in rows and columns.
  • Easy Access – Elements can be accessed using row and column indices.
  • Simplifies Code – One 2D array can replace multiple 1D arrays.
  • Efficient Memory Usage – Stored in contiguous memory locations.
  • Useful in Complex Applications – For matrices, graphs, tabular records.

Uses of Two-Dimensional Array

  • Mathematics (Matrices) – Addition, subtraction, multiplication of matrices.
  • Storing Tabular Data – Example: marks of students in different subjects.
  • Timetables / Schedules – School and college timetables.
  • Game Development – Chess, Sudoku, Tic-tac-toe boards.
  • Image Processing – Images stored as 2D arrays of pixels.
  • Maps and Grids – Used in navigation, pathfinding, and scientific data.

Lesson 2 (Q&A)

 

नियंत्रण कथन (Control Statements)


Part A: बहुविकल्पीय प्रश्न (प्रत्येक 1 अंक)

Q1. निम्नलिखित में से कौन-सा एक घोषणा (declaration) कथन है?
(a) int x;
(b) printf("%d", x);
(c) if(x>0)
(d) for(i=0; i<5; i++)
उत्तर: (a) int x;

Q2. कौन-सी लाइब्रेरी printf() और scanf() उपलब्ध कराती है?
(a) conio.h
(b) stdio.h
(c) string.h
(d) math.h
उत्तर: (b) stdio.h

Q3. printf() में %f का क्या अर्थ है?
(a) पूर्णांक (Integer)
(b) अक्षर (Character)
(c) फ्लोट (Float)
(d) स्ट्रिंग (String)
उत्तर: (c) Float

Q4. स्थिरांक (constant) घोषित करने का सही सिंटैक्स क्या है?
(a) int const MAX=100;
(b) const int MAX=100;
(c) constant int MAX=100;
(d) int MAX=constant 100;
उत्तर: (b) const int MAX=100;

Q5. किस फ़ंक्शन का प्रयोग एक अक्षर का बिना फॉर्मेट वाला इनपुट लेने में होता है?
(a) putchar()
(b) getchar()
(c) gets()
(d) scanf()
उत्तर: (b) getchar()

Q6. कौन-सा फ़ंक्शन एक स्ट्रिंग को नई पंक्ति सहित प्रदर्शित करता है?
(a) puts()
(b) putchar()
(c) printf()
(d) getc()
उत्तर: (a) puts()

Q7. निम्नलिखित में से कौन-सा आधुनिक C में असुरक्षित (unsafe) है?
(a) printf()
(b) gets()
(c) scanf()
(d) puts()
उत्तर: (b) gets()

Q8. एक अभिव्यक्ति कथन (expression statement) हमेशा क्या उत्पन्न करता है?
(a) शर्त (condition)
(b) लूप (loop)
(c) मान (value)
(d) फ़ंक्शन (function)
उत्तर: (c) value

Q9. शर्तीय (conditional) कथन का उदाहरण कौन-सा है?
(a) for
(b) while
(c) if
(d) continue
उत्तर: (c) if

Q10. कौन-सा लूप कम से कम एक बार चलता है?
(a) for
(b) while
(c) do...while
(d) switch
उत्तर: (c) do...while

Q11. कौन-सा जंप (jump) कथन फ़ंक्शन को समाप्त करता है?
(a) break
(b) goto
(c) continue
(d) return
उत्तर: (d) return

Q12. लूप में break क्या करता है?
(a) अगला कथन छोड़ देता है
(b) तुरंत लूप से बाहर निकलता है
(c) लेबल पर जंप करता है
(d) लूप जारी रखता है
उत्तर: (b) Exit loop immediately

Q13. लूप में continue क्या करता है?
(a) प्रोग्राम बंद कर देता है
(b) वर्तमान दोहराव (iteration) छोड़ देता है
(c) अंत तक जंप करता है
(d) प्रोग्राम पुनः आरंभ करता है
उत्तर: (b) Skip current iteration

Q14. कौन-सा कथन बहु-मार्गीय शाखाकरण (multi-way branching) की अनुमति देता है?
(a) if
(b) for
(c) switch
(d) goto
उत्तर: (c) switch

Q15. scanf() में वेरिएबल से पहले कौन-सा चिन्ह प्रयोग होता है?
(a) $
(b) *
(c) &
(d) %
उत्तर: (c) &

Q16. वृद्धि (increment) अभिव्यक्ति का उदाहरण कौन-सा है?
(a) x=5;
(b) x++;
(c) x=y+5;
(d) if(x>y)
उत्तर: (b) x++;

Q17. घोषणा सिंटैक्स में कौन-सा ऑपरेटर प्रयोग होता है?
(a) =
(b) ;
(c) ,
(d) :
उत्तर: (a) =

Q18. एकल अक्षर प्रदर्शित करने हेतु कौन-सा फ़ंक्शन प्रयोग होता है?
(a) putchar()
(b) puts()
(c) printf()
(d) getc()
उत्तर: (a) putchar()

Q19. printf("Age: %d",15); का आउटपुट क्या होगा?
(a) Age: %i
(b) Age: %f
(c) Age: 15
(d) Age: d
उत्तर: (c) Age: 15

Q20. प्रोग्राम के किसी अन्य लेबलयुक्त भाग पर जाने हेतु कौन-सा कथन प्रयोग होता है?
(a) break
(b) continue
(c) return
(d) goto
उत्तर: (d) goto


Part B: अति लघु उत्तरीय प्रश्न (प्रत्येक 1 अंक)

Q1. चर (variable) घोषणा का सिंटैक्स लिखें।
उत्तर: datatype variable_name; (उदा., int x;)

Q2. C में इनपुट/आउटपुट फ़ंक्शन कौन-सी हेडर फाइल देती है?
उत्तर: stdio.h

Q3. %c फॉर्मेट स्पेसिफ़ायर किसका प्रतिनिधित्व करता है?
उत्तर: एक अक्षर (character)।

Q4. घोषणा (declaration) कथन का एक उदाहरण दीजिए।
उत्तर: int a;

Q5. कौन-सा फ़ंक्शन स्पेस सहित स्ट्रिंग पढ़ता है?
उत्तर: gets()

Q6. आधुनिक C में gets() की जगह कौन-सा फ़ंक्शन प्रयोग किया जाता है?
उत्तर: fgets()

Q7. अभिव्यक्ति कथन का एक उदाहरण दीजिए।
उत्तर: x = y + 5;

Q8. कौन-सा शर्तीय कथन कई केस (cases) की अनुमति देता है?
उत्तर: switch कथन।

Q9. for लूप का सिंटैक्स लिखें।
उत्तर: for(initialization; condition; increment/decrement) { //code }

Q10. कौन-सा कथन लूप को तुरंत समाप्त करता है?
उत्तर: break;

Part C : लघु उत्तरीय प्रश्न (प्रत्येक 4 अंक)

Q1. अभिव्यक्ति कथन (Expression statement) और घोषणा कथन (Declaration statement) में अंतर स्पष्ट कीजिए।
उत्तर:

  • घोषणा कथन: इसमें केवल चर (variable) या स्थिरांक (constant) का नाम और डेटा-प्रकार (datatype) दिया जाता है।
    उदाहरण: int x; float y;

  • अभिव्यक्ति कथन: इसमें कोई गणना या मान असाइन (assign) किया जाता है।
    उदाहरण: x = y + 5;


Q2. if-else का उपयोग करते हुए प्रोग्राम लिखिए जो यह जाँच करे कि कोई संख्या सम (even) है या विषम (odd)।
उत्तर:

#include <stdio.h> int main() { int num; printf("कोई संख्या दर्ज करें: "); scanf("%d", &num); if(num % 2 == 0) printf("संख्या सम है"); else printf("संख्या विषम है"); return 0; }

Q3. for लूप का उपयोग कर 1 से 10 तक संख्याएँ प्रदर्शित करने का प्रोग्राम लिखिए।
उत्तर:

#include <stdio.h> int main() { int i; for(i = 1; i <= 10; i++) { printf("%d\n", i); } return 0; }

Q4. while और do...while लूप में क्या अंतर है?
उत्तर:

  • while लूप: शर्त पहले जाँची जाती है, फिर कोड चलता है। यदि शर्त गलत हो तो लूप बिल्कुल नहीं चलेगा।

  • do...while लूप: पहले कोड चलेगा, फिर शर्त जाँची जाएगी। यह लूप कम से कम एक बार अवश्य चलता है।


Q5. switch का उपयोग कर सप्ताह के दिन (1 = रविवार, 2 = सोमवार …) प्रदर्शित करने का प्रोग्राम लिखिए।
उत्तर:

#include <stdio.h> int main() { int day; printf("1-7 तक कोई संख्या दर्ज करें: "); scanf("%d", &day); switch(day) { case 1: printf("रविवार"); break; case 2: printf("सोमवार"); break; case 3: printf("मंगलवार"); break; case 4: printf("बुधवार"); break; case 5: printf("गुरुवार"); break; case 6: printf("शुक्रवार"); break; case 7: printf("शनिवार"); break; default: printf("गलत इनपुट"); } return 0; }

Part D : दीर्घ उत्तरीय प्रश्न (प्रत्येक 8 अंक)

Q1. break और continue कथनों में अंतर उदाहरण सहित स्पष्ट कीजिए।
उत्तर:

  • break: लूप को तुरंत समाप्त कर देता है।

  • continue: वर्तमान iteration छोड़ देता है और लूप की अगली iteration पर चला जाता है।

उदाहरण:

#include <stdio.h> int main() { int i; for(i=1; i<=5; i++) { if(i==3) { continue; // 3 को स्किप करेगा } if(i==5) { break; // 5 आने पर लूप बंद कर देगा } printf("%d\n", i); } return 0; }

Q2. goto कथन का उपयोग कर प्रोग्राम लिखिए जो 1 से 5 तक संख्याएँ प्रदर्शित करे।
उत्तर:

#include <stdio.h> int main() { int i = 1; start: printf("%d\n", i); i++; if(i <= 5) goto start; return 0; }

Q3. return कथन का उपयोग उदाहरण सहित समझाइए।
उत्तर:

  • return का प्रयोग किसी फ़ंक्शन को समाप्त करने और कोई मान (value) वापस भेजने में होता है।

उदाहरण:

#include <stdio.h> int sum(int a, int b) { return a + b; // a+b का मान वापस करेगा } int main() { int result; result = sum(5, 7); printf("योग है: %d", result); return 0; }

Q4. do...while लूप का उपयोग कर 1 से 10 तक संख्याओं का योग (sum) निकालने का प्रोग्राम लिखिए।
उत्तर:

#include <stdio.h> int main() { int i=1, sum=0; do { sum = sum + i; i++; } while(i <= 10); printf("योग = %d", sum); return 0; }

lesson 3 Array (Hindi medium Q&A)

  Array (ऐरे) – प्रश्नोत्तर  Part A: Multiple Choice Questions (1 अंक प्रत्येक) Q1. एक ऐरे (Array) किन प्रकार के मान (values) को संग्रहीत...