Home

A program to explain ARRAY OF POINTERS

C Programming Language 105

Program

#include <stdio.h>

void main()
{
    int a[3][3], i, j, *p[3];

    for (i = 0; i < 3; i++)
    {
        p[i] = a[i];
    }

    printf("Enter elements: ");
    for (i = 0; i < 3; i++)
    {
        for (j = 0; j < 3; j++)
        {
            scanf("%d", p[i] + j);
        }
    }

    printf("Matrix is: \n");

    for (i = 0; i < 3; i++)
    {
        for (j = 0; j < 3; j++)
        {
            printf("%d\t", *(p[i] + j));
        }
        printf("\n");
    }

    printf("\n");
}

Result

Enter elements: 1 2 3 4 5 6 7 8 9
Matrix is:
1       2       3
4       5       6
7       8       9


Last Updated on

Next Post: Rules vs Guidelines →

Comments