title: How do i make a dynamically allocated memory as a globally accessible?
body: <p>How do i make a dynamically allocated memory as a global memory location? </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  char* call(int);
  char *y;
  
  int main() {
      char *a;
      int x;
      x=45;
      a=call(x); \\ I guess it must be pointing to the Memory pointed by y
      printf(a); \\prints hello world
      x=46;
      strcpy(a,"good");
      a=call(x);
      printf(a);
  }
  
  char* call(int x) {
      y=(char *)malloc(40);
      if(x==45) {
          strcpy(y,"hello world");
          return(y);
      } else {
          return(y);
      }
  }
  </code></pre>
  
  <p>I have some questions:</p>
  
  <ol>
  <li><p>Does the memory alloacted by the <code>malloc()</code> stay until the end of program or until the end of the function where it is defined?</p></li>
  <li><p>How do I make <code>a</code> and <code>y</code> point to the same address allocated by the malloc function when they are in different functions?</p></li>
  <li><p>How do I make the dynamically allocated memory globally accessible?</p></li>
  </ol>