Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
edited body
Source Link

I would like to ask why is that giving me seg fault.

  int **a = (int**) malloc (sizeof(int*) * 3);
  a[0][1]a[0][0] = 1;
  a[0][1] = 2;
  a[0][2] = 3;

  for(int i = 0; i < 3; i++)
  {
      printf("%d", a[0][i]);
      //but works with for instance: a[0][1]
  }

I would like to ask why is that giving me seg fault.

  int **a = (int**) malloc (sizeof(int*) * 3);
  a[0][1] = 1;
  a[0][1] = 2;
  a[0][2] = 3;

  for(int i = 0; i < 3; i++)
  {
      printf("%d", a[0][i]);
      //but works with for instance: a[0][1]
  }

I would like to ask why is that giving me seg fault.

  int **a = (int**) malloc (sizeof(int*) * 3);
  a[0][0] = 1;
  a[0][1] = 2;
  a[0][2] = 3;

  for(int i = 0; i < 3; i++)
  {
      printf("%d", a[0][i]);
      //but works with for instance: a[0][1]
  }
Source Link

Problem with pointers, getting seg fault while indexing with variable instead of plain number

I would like to ask why is that giving me seg fault.

  int **a = (int**) malloc (sizeof(int*) * 3);
  a[0][1] = 1;
  a[0][1] = 2;
  a[0][2] = 3;

  for(int i = 0; i < 3; i++)
  {
      printf("%d", a[0][i]);
      //but works with for instance: a[0][1]
  }