#include <stdio.h>
// missing header files for exit, malloc/free, strcpy, etc.

// missing documentation to explain program and its purpose
// maybe copyrights

// need a return type for main
int main() //missing args into main, is it taking any args?
{

  //  char *str = "Hello World"; // assign a constant string, then overriding the
			     // mem addr w/ malloc below.  So this line is
			     // useless.  So just declare the variable w/o
			     // any assignment.
    char *str;

    str = malloc(12); // 11 wasn't enough.
    if (str == NULL) { // malloc failed to alloc memory
      // print some message about "no more memory" (ENOMEM)
      exit(1); // exit w/ non-zero value to indicate program failed.
      // Note: sophisticated programs can try and work around ENOMEM
    }
    //    str = "Hello World"; // overrides return val from malloc, causing
    // a memleak.
    // in C, anything between "double quotes" is an embedded string, or
    // constant string, it is "null" terminated, meaning it has an extra
    // byte of 0 (in C, designated as \0) at the end of the string.  Any
    // str*() functions operate on NULL terminated strings including the
    // extra NULL.
    strcpy(str, "Hello World"); // will copy 11+1=12 bytes, into a buffer
				// that was allocated only bytes.  Meaning
				// that null at the end of the string will
				// have been written to the first byte AFTER
				// the end of the malloc'd buffer.  A buffer
				// overrun/overflow.  So, need to alloc at
				// least 12 bytes above.
    fprintf(stderr, "%s\n", str); // need to use fprintf, not printf
    free(str); // free the mem as soon as done with it, and not before

    // return 0; // main() isn't a regular function, it has no caller to
    // return to, so use exit(3) instead.
    exit(0); // indicating program is terminating successfully
} // should be aligned in same column of opening brace
