title: Segmentation Fault (core dumped). In a Hash Table using separate chaining. (C++)
body: <p>I am currently creating a Hash Table that uses separate chaining as a collision resolution. I implemented a next pointer to the next node in the struct similar to how a linked list would be structured.</p>
  <p>Whenever I attempt to access the next node's word I get a memory error saying Segmentation Fault (core dumped).</p>
  <pre><code>cout&lt;&lt;hashTable[5].next-&gt;word; //this line produces the memory error
  </code></pre>
  <p>What is causing this and how can I fix it?</p>
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  struct Node{
      string word;
      Node* next;
      bool empty;
  };
  
  
  void hashInsert(Node table[], string word){
      int index = 5; //should add hashFunction() if not testing
      Node* current = &amp;table[index];
      if(table[index].empty){
          table[index].word = word;
          table[index].empty = false;
      }
      else{
          while(current-&gt;next != nullptr){
              current = current-&gt;next;
          }
          current = new Node();
          current-&gt;word = word;
          current-&gt;next = nullptr;
          current-&gt;empty = false;
          
      }
  }
  
  
  int main()
  {
  Node hashTable[10];
  hashInsert(hashTable, &quot;test&quot;);
  hashInsert(hashTable, &quot;test&quot;);
  cout&lt;&lt;hashTable[5].next-&gt;word;
  }
  
  </code></pre>