I have the below program in C. How did p[0][0]
become 1? Can somebody help in understanding?
#include <stdio.h>
#include<stdlib.h>
main()
{
int i,j;
int **p=(int **)malloc(2 * sizeof(int *));
p[0]=(int*) malloc(2*sizeof(int));
p[1]=p[0];
for(i=0;i<2;i++)
for(j=0;j<2;j++)
{
p[i][j]=i+j;
printf("%d,%d,%d",i,j,p[i][j]);
printf("\n");
}
printf("%d,%d,%d",i,j,p[0][0]);
}
the output is as below
0,0,0
0,1,1
1,0,1
1,1,2
2,2,1