/* Program for dynamic memory allocation */
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int n, *a, i,j,k;
int p,q, **b;
clrscr();
printf("\n enter the value of n:");
scanf("%d", &n);
// memory allocation to 1-D pointer variable
a=(int *)calloc(sizeof(int), n);
for(i=0;i<n;i++)
{
printf("\n value of a[%d] is %d", i, a[i]);
}
printf("\n enter the values of p and q");
scanf("%d%d",&p,&q);
// memory allocaation to 2-D pointer varaible
b=(int **)calloc(sizeof(int *), p);
for(i=0;i<p;i++)
{
b[i]=(int *)calloc(sizeof(int),q);
}
k=100;
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
b[i][j]=k; k++;
}
}
for(i=0;i<p;i++)
{
printf("\n");
for(j=0;j<q;j++)
{
printf("\t %d",*(*(b+i)+j));
}
}
getch();
}