title: Shared memory between parent and child on fork C++
body: <p>I am new to C++. Is it possible to declare a variable for shared use between parent and child processes in fork()?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/wait.h&gt;
  
  using namespace std;
  
  int var;
  
  int main(int argc, char * argv[])
  {       
      pid_t child_pid;
      int status;
  
      var = 3;
  
      if ((child_pid = fork()) &lt; 0) {
          perror("Error (fork failure)");
      }   
  
      if (child_pid == 0) {
        var = 10;
        cout &lt;&lt; "CHILD ASSIGNED var=" &lt;&lt; var &lt;&lt; endl;
      }    
      else {        
          wait(NULL);
          cout &lt;&lt; "PARENT var=" &lt;&lt; var &lt;&lt; endl;
      }                        
  }
  </code></pre>
  
  <p>The current result I get is:</p>
  
  <pre><code>CHILD ASSIGNED var=10
  PARENT var=3
  </code></pre>
  
  <p>What I want is </p>
  
  <pre><code>PARENT var=10
  </code></pre>