The following code gives me a segmentation fault. I thinks its an issue with the syntax of realloc. Please advise.
#include <stdio.h>
#include <stdlib.h>
main()
{
int **arr;
int i,k, j;
arr = (int **) malloc (3);
arr[0] = (int *) malloc (2);
arr[1] = (int *) malloc (2);
arr[2] = (int *) malloc (2);
arr[0][0] = 9;
arr[0][1] = 21;
arr[1][0] = 44;
arr[1][1] = -9;
arr[2][0] = 12;
arr[2][1] = 22;
for (i=0;i<3;i++)
for (k=0;k<2;k++)
printf("\narr[%d][%d] = %d\n", i,k, arr[k]);
arr[0] = (int *) realloc (arr[0],(sizeof(arr[0]) + 1));
arr[0][2] = 234;
printf("\narr[0][2] = %d\n", arr[0][2]);
}
#include <stdio.h>
#include <stdlib.h>
main()
{
int **arr;
int i,k, j;
arr = (int **) malloc (3);
arr[0] = (int *) malloc (2);
arr[1] = (int *) malloc (2);
arr[2] = (int *) malloc (2);
arr[0][0] = 9;
arr[0][1] = 21;
arr[1][0] = 44;
arr[1][1] = -9;
arr[2][0] = 12;
arr[2][1] = 22;
for (i=0;i<3;i++)
for (k=0;k<2;k++)
printf("\narr[%d][%d] = %d\n", i,k, arr[k]);
arr[0] = (int *) realloc (arr[0],(sizeof(arr[0]) + 1));
arr[0][2] = 234;
printf("\narr[0][2] = %d\n", arr[0][2]);
}