C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 12-16-2008, 02:25 PM   #1
Registered User
 
Join Date: May 2006
Posts: 181
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?
yougene is offline   Reply With Quote
Old 12-16-2008, 02:31 PM   #2
Frequently Quite Prolix
 
dwks's Avatar
 
Join Date: Apr 2005
Location: Canada
Posts: 7,698
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.
dwks is offline   Reply With Quote
Old 12-16-2008, 02:43 PM   #3
Registered User
 
Join Date: May 2006
Posts: 181
Ahh, thank you.
yougene is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
help with basic program JOlszewski C Programming 3 02-01-2006 04:19 PM
program not working...please look at this JOlszewski C Programming 3 01-30-2006 10:33 PM


All times are GMT -6. The time now is 05:54 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22