A function prototype declares the function's name, the types
of its parameters, and its return type, without providing the
body of the function. It promises the compiler that the function
will be defined, so that we can include code using the function
before the function definition is itself encountered.
One particularly important place where this is necessary is when the
function is used in one C file (so the code in that file uses it
without having a definition of how it works) but defined in another
create_pointer function returns a pointer to its
local variable, so
p variable ends up
pointing to that local variable
k is deallocated upon
return, and that same memory can be used for other purposes.
This is what Ben found; as it happens, that memory was used for
another purpose, and the program happens to have placed the number 32,610
into that memory (which was done by
printf, by the way).
p is still pointing to that memory location, so
when we dereference
p, it displays the value currently in
Space for functions' local variables are allocated from the
stack, and the space for each local variable is deallocated when
the function owning the variable returns.
We allocate space on the heap only through the
function; space allocated in this way remains allocated until
the program later calls
This is an artifact of the teletypes (electrically controlled
typewriters) in heavy use at the time that ASCII was developed.
For a typewriter, there are two actions involved in going to the next line:
moving the print carriage back to the beginning of line (CR, for
Carriage Return) and scrolling the paper up one
line (LF, for Line Feed. Many systems have
preserved this until today.