title: Can I use "malloc" for local variables to return local variables?
body: <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;ctype.h&gt;
  
  char * upperCase(const char* s)
  {
      char * ret = NULL;
      size_t length = strlen(s) + 1;
      ret = (char*)malloc(sizeof(char) * length);
      for (size_t i = 0; i &lt; length; i++) {
          ret[i] = toupper(s[i]);
      }
      return ret;
  }
  
  int main()
  {
      char* ret = NULL;
      char* input = &quot;HelloWorld&quot;;
      ret = upperCase(input);
      printf(&quot;value = %s&quot;, ret);
      free(ret);
  }
  </code></pre>
  <blockquote>
  <p>The above code takes a string as a parameter and copies the string. It
  then converts each element of the copied string to uppercase and
  returns it.</p>
  <p>Compiler = GCC 6.2</p>
  </blockquote>
  <p>If you use the malloc function, is it possible to return a local variable to terminate the function and release the memory? I do not have enough understanding of the scope that still has memory.</p>