C Program To Understand Use Of Pointers In MATRIX

How to write a C Program To Understand Use Of Pointers In MATRIX in C Programming Language ?


Solution For C Program :

/*C Program To Understand Use Of Pointers In MATRIX.*/


/*Accessing matrix elements & their address using pointer*/
#include<stdio.h>
#include<conio.h>
int i,j;
void main()
{
int mat1[3][3]={{11,12,13},{14,15,16},{17,18,19}};
clrscr();
printf("First Entered matrix is:\n");
for(i=0;i<3;i++)
    {
    printf("\n");
    for(j=0;j<3;j++)
        {
        printf("\t%d",mat1[i][j]);
        }
    }
printf("\n\n Address of first row  =%u",mat1);
printf("\n Address of Second row =%u",mat1+1);
printf("\n Address of Third row  =%u\n",mat1+2);
printf("\n Address of\t(0,0) =%u",*(mat1+0)+0);
printf("\t (0,1) =%u",*(mat1+0)+1);
printf("\t (0,2) =%u",*(mat1+0)+2);
printf("\n Address of\t(1,0) =%u",*(mat1+1)+0);
printf("\t (1,1) =%u",*(mat1+1)+1);
printf("\t (1,2) =%u",*(mat1+1)+2);
printf("\n Address of\t(2,0) =%u",*(mat1+2)+0);
printf("\t (2,1) =%u",*(mat1+2)+1);
printf("\t (2,2) =%u",*(mat1+2)+2);

printf("\n\n Value at\t(0,0) =%d",*(*(mat1+0)+0));
printf("\t (0,1) =%d",*(*(mat1+0)+1));
printf("\t (0,2) =%d",*(*(mat1+0)+2));
printf("\n Value at\t(1,0) =%d",*(*(mat1+1)+0));
printf("\t (1,1) =%d",*(*(mat1+1)+1));
printf("\t (1,2) =%d",*(*(mat1+1)+2));
printf("\n Value at\t(2,0) =%d",*(*(mat1+2)+0));
printf("\t (2,1) =%d",*(*(mat1+2)+1));
printf("\t (2,2) =%d",*(*(mat1+2)+2));

getch();
}



You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable



Learn More :