Donate to Grow My Website (1 $ please)

  • You may choose specified posts to show it as featured posts with automatic sliding effects and keep visitors engaged for long time on your sites.
  • Dec 14, 2018

    Multidimensional Array in Data Structure - Learnengineeringforu

    Multidimensional Array in Data Structure - Learnengineeringforu

    Multidimensional array

    1. Array having more than one subscript variable is called multidimensional array.
    2. Multidimensional array is also called as matrix.

    Consider the Two dimensional array –

    1. Two Dimensional Array requires Two Subscript Variables
    2. Two Dimensional Array stores the values in the form of matrix.
    3. One Subscript Variable denotes the “Row” of a matrix.
    4. Another Subscript Variable denotes the “Column” of a matrix.

    Declaration and Use of Two Dimensional Array :

    int a[3][4];
    Use :
    for(i=0;i<row,i++)
       for(j=0;j<col,j++)
       {
       printf("%d",a[i][j]);
    }

    Meaning of Two Dimensional Array :

    1. Matrix is having 3 rows ( i takes value from 0 to 2 )
    2. Matrix is having 4 Columns ( j takes value from 0 to 3 )
    3. Above Matrix 3×4 matrix will have 12 blocks having 3 rows & 4 columns.
    4. Name of 2-D array is ‘a‘ and each block is identified by the row & column number.
    5. Row number and Column Number Starts from 0.
    Cell LocationMeaning
    a[0][0]0th Row and 0th Column
    a[0][1]0th Row and 1st Column
    a[0][2]0th Row and 2nd Column
    a[0][3]0th Row and 3rd Column
    a[1][0]1st Row and 0th Column
    a[1][1]1st Row and 1st Column
    a[1][2]1st Row and 2nd Column
    a[1][3]1st Row and 3rd Column
    a[2][0]2nd Row and 0th Column
    a[2][1]2nd Row and 1st Column
    a[2][2]2nd Row and 2nd Column
    a[2][3]2nd Row and 3rd Column

    Two-Dimensional Array : Summary with Sample Example

    Summary PointExplanation
    No of Subscript Variables Required2
    Declarationa[3][4]
    No of Rows3
    No of Columns4
    No of Cells12
    No of for loops required to iterate2

    Memory Representation

    1. 2-D arrays are Stored in contiguous memory location row wise.
    2. 3 X 3 Array is shown below in the first Diagram.
    3. Consider 3×3 Array is stored in Contiguous memorylocation which starts from 4000 .
    4. Array element a[0][0] will be stored at address 4000 again a[0][1] will be stored to next memory location i.e Elements stored row-wise
    5. After Elements of First Row are stored in appropriate memory location , elements of next row get their corresponding mem. locations.
    1. This is integer array so each element requires 2 bytes of memory.

    Basic Memory Address Calculation :

    a[0][1] = a[0][0] + Size of Data Type
    
    ElementMemory Location
    a[0][0]4000
    a[0][1]4002
    a[0][2]4004
    a[1][0]4006
    a[1][1]4008
    a[1][2]4010
    a[2][0]4012
    a[2][1]4014
    a[2][2]4016


    No comments:
    Write Comments