This might be very silly question to ask.
I am using malloc to memory allocation.
Program compiles fine but segmentation fault occurs while launching.
Here is min code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
int row,col,i;
int **mat;
row = 3; //made row as static for testing
col = 4; //made col as static for testing
*mat = (int *)malloc(sizeof(int)*row);
for (i=0;i<row;i++)
mat[i] = (int *) malloc (sizeof(int)*col);
}
i compiled with: gcc -ggdb test.c
on gdb its giving:
(gdb) run
Starting program: /slowfs/swe91/abjoshi/clients/fw_cl_for_seg_fault/a.out
Program received signal SIGSEGV, Segmentation fault.
0x00000000004004cc in main () at 1test.c:10
10 *mat = (int *)malloc(sizeof(int)*row);
Note: gcc version 4.5.2