tags:

views:

241

answers:

1

Whats wrong with this?I am getting segmentation fault during runtime.

int size;
scanf("%d",&size);
int init[size][size];
 //initial matrix
for(int i=0;i<size;i++)
  for(int j=0;j<size;j++)
     scanf("%d",init[i][j]);
+3  A: 

You need &init[i][j] rather than init[i][j] in scanf().

qrdl
it works but i thought init[i][j] also points to address of init[i][j].
I think you mix it us with pointer arithmetics. init+i*size+j indeed will be *int, but init[i][j] will give you array element, which is int.
qrdl