Thread: Understanding creation of destruction and creation of data types

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    182

    Understanding creation of destruction and creation of data types

    In my book it says "We can apply static to a local array declaration so the array is not created and initialized each time the function is called and the array is not destroyed each time the function is exited in the program."


    When an array is created where exactly is the creation taking place? In the ram?

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Yes, variables are created "in memory", which is almost always the RAM.

    Where exactly in RAM variables are created varies. "Normal" or automatic variables, for example (variables that you declare normally inside of a function), are created on the stack, and are of course destroyed when the function exits. Static and global variables are created somewhere else, in memory that is only initialized once (when the program starts) and destroyed once (when the program exits). Dynamically allocated variables (malloc()'d ones) are created on the heap, and persist until they are freed manually (by calling free()).
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    182
    Ahh, thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with basic program
    By JOlszewski in forum C Programming
    Replies: 3
    Last Post: 02-01-2006, 04:19 PM
  2. program not working...please look at this
    By JOlszewski in forum C Programming
    Replies: 3
    Last Post: 01-30-2006, 10:33 PM