Unit 4. Array with Pavan Chavhan.





Myself Pavan Chavhan, I'm very happy to see all of you here  I welcome you all from bottom of my hearts. Today I'm going to share a blog on "technical_spc" regarding unit 4 of "C programming" i.e. Array. So I hope everyone must be eager to learn this new topic. Let's start with our new topic without making any delay. 



Introduction.



(a). An array is defined as the collection of similar type of data items stored at contiguous memory locations.

(b). The array is the simplest data structure where each data element can be randomly accessed by using its index number.

(c). Each element of an array is of same data type and carries the same size.

(d). Elements of the array are stored at contiguous memory locations where the first element is stored at the smallest memory location.

(e). Elements of the array can be randomly accessed since we can calculate the address of each element of the array with the given base address and the size of the data element.




 

Declaring array.



  • type array Name [ array Size ];



Initializing array.


  • double balance[5] = {1000.0, 2.0, 3.4, 17.0, 50.0};

  • The number of values between braces { } can not be larger than the number of elements that we declare for the array between square brackets [ ]. 






Example :-

  • Program :-




  • Output :-





Two dimensional array.



  • The two-dimensional array can be defined as an array of arrays. The 2D array is organized as matrices which can be represented as the collection of rows and columns.


Declaration of two dimensional array.



  • data type array name[rows][columns];


Initialisation of 2D array.



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


Example :-

  • Program :-




  • Output :-



  • We already know, when we initialize a normal array (or you can say one dimensional array) during declaration, we need not to specify the size of it. However that’s not the case with 2D array, you must always specify the second dimension even if you are specifying elements during the declaration.



If you have any questions you may ask in comment below. If you enjoyed this article, share it with your friends and colleagues!






Post a Comment

0Comments

If you have any doubts, Please let me know

Post a Comment (0)