title: C++ function returned value not assigned
body: <p>I encountered a weird bug</p>
  
  <p>I am returning a pointer, before return, I verified that the pointer is valid &amp; has memory
  However, after the function scope, when I tried to use the return value in main(), it becomes NULL.
  I also tried to return the dereferenced value of the pointer, it is a modified struct before return, and an unmodified struct in main()..</p>
  
  <p>This is supposed to be like a dictionary</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include "trie.h"
  
  using namespace std;
  
  int alphaLoc(char segment){
      return (int)segment - 97;
  }
  
  //inserts a word in the tree
  void insert(TrieNode &amp;node, const std::string &amp;word){
      int locationInAlphabet = alphaLoc(word[0]);
      if (node.letters[locationInAlphabet] == NULL){
          node.letters[locationInAlphabet] = new TrieNode;
      }
      if (word.length() == 1){
          if (node.letters[locationInAlphabet]-&gt;isWord == true){
              cout&lt;&lt;"Word Already Exsit"&lt;&lt;endl;
          }
          node.letters[locationInAlphabet]-&gt;isWord = true;
      }
      else{
          insert(*(node.letters[locationInAlphabet]), word.substr(1,word.length()-1));
      }
  }
  
  //returns the node that represents the end of the word
  TrieNode* getNode(const TrieNode &amp;node, const std::string &amp;word){
      int locationInAlphabet = alphaLoc(word[0]);
      if (node.letters[locationInAlphabet] == NULL){
          return NULL;
      }
      else{
          if (word.length() == 1){
              return (node.letters[locationInAlphabet]);
          }
          else{
              getNode(*(node.letters[locationInAlphabet]), word.substr(1,word.length()-1));
          } 
      }
  }
  
  int main(){
      TrieNode testTrie;
      insert(testTrie, "abc");
      cout&lt;&lt; testTrie.letters[0]-&gt;letters[1]-&gt;letters[2]-&gt;isWord&lt;&lt;endl;
      cout&lt;&lt;"testing output"&lt;&lt;endl; 
      cout&lt;&lt; getNode(testTrie, "abc")-&gt;isWord &lt;&lt; endl;
      return 1;
  }
  </code></pre>
  
  <p>And the output is :</p>
  
  <pre><code>1
  testing output
  Segmentation fault: 11
  </code></pre>
  
  <p>trie.h:</p>
  
  <pre><code>#include &lt;string&gt;
  
  struct TrieNode {
      enum { Apostrophe = 26, NumChars = 27 };
      bool isWord;
      TrieNode *letters[NumChars];
      TrieNode() {
          isWord = false;
           for ( int i = 0; i &lt; NumChars; i += 1 ) {
               letters[i] = NULL;
           } // for
      }
  }; // TrieNode
  
  void insert( TrieNode &amp;node, const std::string &amp;word );
  
  void remove( TrieNode &amp;node, const std::string &amp;word );
  
  std::string find( const TrieNode &amp;node, const std::string &amp;word );
  </code></pre>