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]);

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.