EmbLogic's Blog

ARRAY: the name of confusion

#include <stdio.h>
int main()
{
int a[5][5],c[5][5],i,j;
int b[2][3]={{1,2,3},{3,4,5}};

        for(i=0;i<5;i++)
        {
        for(j=0;j<5;j++)
        {
        printf(“array B: %d\n”,b[i][j]);
        printf(“enter array A: “);
        scanf(“%d”,&a[i][j]);
        c[i][j]=a[i][j]+b[i][j];
        printf(“c[%d}[%d] : %d \n\n  “,i,j,c[i][j]);
}

}
return 0;

}

OUTPUT:

 

array B: 1
enter array A: 2
c[0}[0] : 3

  array B: 2
enter array A: 2
c[0}[1] : 4

  array B: 3
enter array A: 2
c[0}[2] : 5

  array B: 3
enter array A: 2
c[0}[3] : 5

  array B: 4
enter array A: 2
c[0}[4] : 6

  array B: 3
enter array A: 2
c[1}[0] : 5

  array B: 4
enter array A: 2
c[1}[1] : 6

  array B: 5
enter array A: 2
c[1}[2] : 7

  array B: 3
enter array A: 2
c[1}[3] : 5

  array B: 4
enter array A: 2
c[1}[4] : 6

  array B: 3
enter array A: 2
c[2}[0] : 5

  array B: 4
enter array A: 2
c[2}[1] : 6

  array B: 5
enter array A: 2
c[2}[2] : 7

  array B: 5
enter array A: 2
c[2}[3] : 7

  array B: 6
enter array A: 2
c[2}[4] : 8

  array B: 5
enter array A: 2
c[3}[0] : 7

  array B: 6
enter array A: 2
c[3}[1] : 8

  array B: 5
enter array A: 2
c[3}[2] : 7

  array B: 6
enter array A: 2
c[3}[3] : 8

  array B: 7
enter array A: 2
c[3}[4] : 9

  array B: 6
enter array A: 2
c[4}[0] : 8

  array B: 7
enter array A: 2
c[4}[1] : 9

  array B: 5
enter array A: 2
c[4}[2] : 7

  array B: 6
enter array A: 2
c[4}[3] : 8

  array B: 5
enter array A: 2
c[4}[4] : 7

 

Q-1ARRAY b[2][3] IS BEING INITIALISED..Then how is compiler giving other values as shown in OUTPUT??
2)  IF ITZ ABOUT CHECK-BOUND,,then give the complete justification..coz here we r INITIALISING AN ARRAY , not inputing IT??

One Response to ARRAY: the name of confusion

  1. hemant.kumar says:

    there is no check boundation in arrays ..
    for(i=0;i<2;i++)
    {
    for(j=0;j<3;j++)
    {
    printf("array b is %d\n",b[i][j]);
    }
    once you go beyond the limits you have provided it will give you the garbage values..b[1][2]=5 i.e 1st low and 2nd column
    b[1][3] =4(garbage value) because in array b you declared two rows and three columns ..
    in your program..
    for(i=0;i<5;i++)
    {
    for(j=0;j<5;j++)
    {
    printf(“array B: %d\n”,b[i][j])
    }
    it will take garbage values including your declared values{1,2,3},{3,4,5}
    and garbage values can be as same as
    declared values so dont get confuse ..

Leave a Reply to hemant.kumar Cancel reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>