Remember that you cannot use, int **p for this purpose, or even int *p[4] for this purpose.
#include <stdio.h>
#include <malloc.h>
main()
{
int i, j;
int a[3][4];
int (*p)[4];
int size = 3;
p = (int (*)[4])malloc(12*4);
for(i=0; i<3; i++)
for(j=0; j<4; j++)
{
p[i][j] = i+j;
a[i][j] = p[i][j];
}
for(i=0; i<3; i++)
{
for(j=0; j<4; j++)
printf("%d ", a[i][j]);
printf("\n");
}
}
Have a nice time, and enjoy programming.!
No comments:
Post a Comment