Array Of C Programming In HINDI

जब हम लोग किसी Program को बनाने के लिए एक ही types के बहुत सारे data को store करके access व manipulate करना होता है तब हम similar type data को store करने के लिए बहुत सारे variables create करने पड़ते हैं जिससे हमारे program की length और complexcity बढ़ जाती है!

Array Of C Programming i HINDI

C language में इसी condition को देखते हुए  arrays के द्वारा ऐसी facility provide कराई गई 
कि आप सिर्फ एक variable create करें और उस variable में employees के name इनका details और किसी भी information को आसानी से store कर  सकते हैं और जरूरत पड़ने पर  उसे access भी कर सकते हैं!

             आप सोच रहे होंगे कि एक variables में इतने सारे नाम और details कैसे Store करेंगे इसके बारे में मुझे आपको बताने में बहुत खुशी होगी लेकिन उससे पहले आइए हम यह जानने की कोशिश करते हैं कि arrays क्या है और इसका use हम कैसे करें कि हमारा program आसान हो सके !

What is Array in HINDI                   

1. C language में array एक fixed structured  data type होता है!

2.Array एक similar type data items का collection होता है!                                
     Viz:-int,float,char,etc

3.Array का initialization zero से start होता है!

4.किसी भी array का size and name को अगर एक बार defined कर दिया गया हो तो उसको हम दोबारा modify नहीं कर सकते हैं!

5.प्रत्येक data items को array का element कहते हैं!

6.Array के हर elements को uniquely identify करने के लिए उसके साथ एक zero base unique index number को specified करते हैं!

7.Array के सभी data items memory में एक definite sequence में store होते हैं!

8.Array similar type data items को store करने के लिए memory के heap area को use करता है और data items को store करने के लिए continues memory locations का use करता है!

 ________________________

      roll-no[0]
     /             \
  array     Subscription
  variable
________________________
               
Note:- Array का element same variable name share करते हैं लेकिन इसमे प्रत्येक element का एक different index होता है जिसे हम subscripts कहते हैं

Array are two types

1.One Dimensional Array

2.Multi Dimensional Array

Declaration of 1-D Array

  • किसी भी Array का Dimension one हो उस Array को linear या one Dimensional Array कहते हैं|
  • इसके elements को access करने के लिए एक single subscript का use करते हैं जो हमें row या column index को represent करता है|
  • Syntax:- data type array name[size];
  • data type:-यह Array में elements के type को denotes करता है|
  • array name:- Name of the Array it must be a valid identifier.
  • Size:- यहां पर number of element hold करते हैं|

Some example of Array declaration.

1.  int age [100];
2. float salary [20];
3. char grade [50];

Hints:- Age is an array of type int which  can store 100 elements of type int.
The array  salary is a float type array of size 15. hold float.             
Grade character type array of size 20 Can hold characters.
Note- Array is declared if it is contain garbage values.
             

The individual elements of the above arrays are


  • age[0],age[1],age[2] .................age[99]
  • salary[0],salary[1],salary[2].....salary[14]
  • grade[1],grade[2],grade[3]........grade[19]

•  जब कोई Array declared किया जाता है तो compiler में Array के सभी elements को रखने के लिए memory location पर allocate किया जाता है इसलिए Array का size compile time पर मालूम होना चाहिए|

•  Declaration में Array के size को specify करने के लिए हम variables का use नहीं कर सकते हैं|

•  Array के size को specify करने के लिए symbolic constant का use कर सकते हैं|

   Viz:- #define SIZE 10
             int main(void)
            {
              int size =15;
              float salary [size];           /*valid*/
              int marks [size];            /*Not valid*/ 
              ..........................
              ..........................
              ..........................
            }

Accessing Of 1-D Array Elements

  • किसी array के elements को brackets में subscript के बाद array के नाम को specify करके access किया जा सकता है|
  • In C the array subscript start from zero.
  • माना कि किसी array की size 5 है तो उसका valid subscript 0,1,2,3,4 होगा
  • Last वाला जो valid subscript है वह array के size से one कम होगा
  • Last वाले valid subscript को array का upper bound और zero को lower bound कहते हैं|
Viz:- int [5];

/* size of array arr is 5,can hold five integer elements */

The elements of this array are-

array [0] , array [1] , array [2] , array [3] , array [4]

Note:-

  • यहां पर zero lower bound है और 4 array की upper bound है|
  • if i and j are integer variables then these are some valid subscripted array  elements.

array [i]  array [j]  array [2*j]  array [I+j]  array [i++]

Viz:-if arr and sal are two array of size 5 and 10 respectively,then come and see these valid statements.

        int arr [5];

        float sal [10];

        int i;

        scanf("%d'',&arr [1]);       /*input value into arr [1]*/

        printf("%f",sal [3]);.         /*print value of sal [3]*/

        arr [4]=25;          /*assign a value to arr [4]*/

        arr [4] ++;                  b/*increment the value of arr [4] by 1*/

 sal [5] +=200;            /*Add 200 to sal [5]*/

       sum=arr [0]+arr [1]+arr [2]+arr [3]+arr [4];        /*Add all the values of array arr [5]*/

i=2;

scanf("%f",&sal [i]);         /*input value into sal [2]*/

Printf("%f",sal [i]);     /*print value of sal[2]*/

Printf("%f",sal [i++]);    /*print value of sal[2] and increment the value of i*/

Note:-if someone tries to access element beyond these subscripts,like arr[5],arr[10], the compiler will not show any error message but this may lead to run time errors.so it is the responsibility of programmer to provide array bounds checking wherever needed.

Processing Of 1-D Array

  • Array के processing के लिए generally for loop का इस्तेमाल होता है|
  • Loop variable का use subscript के स्थान पर किया जाता है|
  • Loop variable का initial value zero लिया जाता है क्योंकि subscript zero से start होता है|
  • The total number of passes in the loop will be equal to the number of elements in the array and in the array and each pass we will process one element.
  1. Reading value in arr
         for (i=0; i<5; i++)
                 scanf ("%d",&arr [i]);

    2.Displaying values of arr
         for (i=0; i<5; i++) 
                Printf ("%d", arr [i] );

    3. Adding all the elements of arr
          sum =0;
          for(i=; i<5; i++)  
                   sum+ = arr [i] ;

/* Program to input values into an array and display them*/

      #include <stdio.h>
        int main(void)
       {
               int   arr [5] , i ;
                 for ( i=0; i<5; i++)
             {
                 Printf(" Enter a value for arr[%d]  :  ",i );
                    scanf("%d", &arr [i] );
             }
                Printf(" The array elements are   : \n ");
                    for ( i=0; i<5; i++)
                        Printf (" %d\t ", arr [i] );
                Printf ( "\n" );
                return 0;
        }
 
OUTPUT:- 
 Enter a value for arr[0] : 23
 Enter a value for arr[1] : 12
 Enter a value for arr[2] : 15
 Enter a value for arr[3] : 59
 Enter a value for arr[4] : 21
 The array elements are :
 23      12      15      59      21

Enter your no :
1
Enter your no :
2
Enter your no :
3
Enter your no :
4
Enter your no :
5
[0] - 1
[1] - 2
[2] - 3
[3] - 4
[4] - 5