title: When should I use malloc in C and when don't I?
body: <p>I understand how malloc() works. My question is, I'll see things like this:</p>
  
  <pre><code>#define A_MEGABYTE (1024 * 1024)
  
  char *some_memory;
  size_t size_to_allocate = A_MEGABYTE;
  some_memory = (char *)malloc(size_to_allocate);
  sprintf(some_memory, "Hello World");
  printf("%s\n", some_memory);
  free(some_memory);
  </code></pre>
  
  <p>I omitted error checking for the sake of brevity. My question is, can't you just do the above by initializing a pointer to some static storage in memory? perhaps:</p>
  
  <pre><code>char *some_memory = "Hello World";
  </code></pre>
  
  <p>At what point do you actually need to allocate the memory yourself instead of declaring/initializing the values you need to retain?</p>