Skip to main content
Edited answer with no changes to remove my downvote.
Source Link
Cliff B
  • 69.3k
  • 4
  • 33
  • 56

Initially you have declared node *table[N] as global pointer. As you might have already guessed, all global variables/ pointers are set to default values.(In this case, each pointer is set to NULL).

So head = table[hash_index]; // It's still NULL

When you do head->next, you're trying to de-reference NULL which results in seg-fault.

Initially you have declared node *table[N] as global pointer. As you might have already guessed, all global variables/ pointers are set to default values.(In this case, each pointer is set to NULL).

So head = table[hash_index]; // It's still NULL

When you do head->next, you're trying to de-reference NULL which results in seg-fault.

Initially you have declared node *table[N] as global pointer. As you might have already guessed, all global variables/ pointers are set to default values.(In this case, each pointer is set to NULL).

So head = table[hash_index]; // It's still NULL

When you do head->next, you're trying to de-reference NULL which results in seg-fault.

added 6 characters in body
Source Link
C--
  • 306
  • 1
  • 11

Initially you have declared node *table[N] as global pointerglobal pointer. As you might have already guessed, all global variables/ pointers are set to default values.(In this case, each pointer is set to NULL).

So head = table[hash_index]; // It's still NULL

When you do head->next, you're trying to de-reference NULL which results in seg-fault.

Initially you have declared node *table[N] as global pointer. As you might have already guessed, all global variables/ pointers are set to default values.(In this case, each pointer is set to NULL).

So head = table[hash_index]; // It's still NULL

When you do head->next, you're trying to de-reference NULL which results in seg-fault.

Initially you have declared node *table[N] as global pointer. As you might have already guessed, all global variables/ pointers are set to default values.(In this case, each pointer is set to NULL).

So head = table[hash_index]; // It's still NULL

When you do head->next, you're trying to de-reference NULL which results in seg-fault.

Source Link
C--
  • 306
  • 1
  • 11

Initially you have declared node *table[N] as global pointer. As you might have already guessed, all global variables/ pointers are set to default values.(In this case, each pointer is set to NULL).

So head = table[hash_index]; // It's still NULL

When you do head->next, you're trying to de-reference NULL which results in seg-fault.