[prev] 62 [next]

The malloc() function (cont)

malloc() returns a pointer to a data object of some kind.

Things to note about objects allocated by malloc():

  • they contain random values
    • need to be initialised before they are read
  • they exist until explicitly removed   (program-controlled lifetime)
  • they are accessible while some variable references them
  • if no active variable references an object, it is garbage
The function free() releases objects allocated by malloc()