title: How to get value of variable outside child process that i store in variable in child process?
body: <p>i am storing data in variable in child process and when i get value outside child process it returns me garbage value. But when i get value of variable (that i stored in the variable in the child process) in the child process it gives me correct value.
  My code is given below. Thanks in advance.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  
  void getValues();
  void printValues();
  
  int main()
  {
  int cpid, i = 0, j = 0, mat1[4], mat2[4], mat3[4], mat4[4], mat[4], sum1[4], sum2[4];
  //get values in all matrixes.
  for(i=0; i &lt; 4; i++)
      {
          printf("\nEnter value %d in matrix 1: ", i+1);
          scanf("%d", &amp;mat1[i]);
      }
  
      for(i=0; i &lt; 4; i++)
      {
          printf("\nEnter value %d in matrix 2: ", i+1);
          scanf("%d", &amp;mat2[i]);
      }
  
  for(i=0; i &lt; 4; i++)
      {
          printf("\nEnter value %d in matrix 3: ", i+1);
          scanf("%d", &amp;mat3[i]);
      }
  
      for(i=0; i &lt; 4; i++)
      {
          printf("\nEnter value %d in matrix 4: ", i+1);
          scanf("%d", &amp;mat4[i]);
      }
   //print values of all matrixes.
  printf("\nMatrix 1:\n");
      for(i=0; i &lt; 4; i++)
      {
          printf("%d\t", mat1[i]);
          if(i == 1)
          {
              printf("\n");
          }
      }
  
      printf("\n\nMatrix 2:\n");
      for(i=0; i &lt; 4; i++)
      {
          printf("%d\t", mat2[i]);
          if(i == 1)
          {
              printf("\n");
          }
      }
  
      printf("\n\nMatrix 3:\n");
      for(i=0; i &lt; 4; i++)
      {
          printf("%d\t", mat3[i]);
          if(i == 1)
          {
              printf("\n");
          }
      }
  
      printf("\n\nMatrix 4:\n");
      for(i=0; i &lt; 4; i++)
      {
          printf("%d\t", mat4[i]);
          if(i == 1)
          {
              printf("\n");
          }
      }
  
  cpid = fork();
  
  if(cpid &lt; 0)
  {
      printf("\n\nFaild!\n\n");
  }
  if(cpid == 0)
  {
      for(i=0; i &lt; 4; i++)
      {
          sum1[i] = mat1[i] + mat2[i];
      }
  }
  else
  {
      for(i = 0; i &lt;=10000; i++)
      {for(j = 0; j&lt;=10000; j++){}}
  
  for(i=0; i &lt; 4; i++)
      {
          sum2[i] = mat3[i] + mat4[i];
      }
  
  for(i=0; i &lt; 4; i++)
      {
          mat[i] = sum1[i] + sum2[i];
      }
  
  printf("\nSum of All Matrixes:\n");
      for(i=0; i &lt; 4; i++)
      {
          printf("%d\t", mat[i]);
          if(i == 1)
          {
              printf("\n");
          }
      }
  
  }
  }
  </code></pre>