difference between static and dynamic allocations

when writing char name[25] and allocating "toto" for example it seems like a dynamic allocation though its static so what the difference between static and dynamic allocations and can we use pointers to point on a static variable or static array and thanks
Static Allocation

Statically allocated variables have their storage allocated and initialized before main starts running and are not deallocated until main has terminated. Statically allocated local variables are not re-initialized on every call to the function in which they are declared. A statically allocated variable thus has the occasionally useful property of maintaining its value even when none of the functions that access the variable are active.

Dynamic Allocation

Static and automatic array variables, although different in essential ways, have a common limitation. The programmer must choose sizes for them before the program is compiled, so he or she must make a guess at what might be the largest reasonable amount of data a program might have to handle. If the guess is too low, some users will be irritated because the program can't handle the data belonging to the problems those users want to solve. If the guess is too high, the program might not be usable on computers with relatively little available memory.

One solution to this problem is to let the program determine how much memory it needs at run time, and allocate exactly the right amount of storage. This is called dynamic memory allocation. Typical uses of dynamic memory allocation are:

* creation of dynamic arrays - arrays whose sizes are chosen at run time;
* creation of dynamic data structures - data collections that grow and shrink with the changing data storage needs of a program or module.


I copied this from [http://enel.ucalgary.ca/People/Norman/engg333_fall1996/stat_dyn/]
Hope that helps :-)
yes thanks a lot the infos were quite interresting especially when talking about the heap it seemed that the allocation of 25 bytes in char name[25] then just allocating 4 bytes for toto a big waste of memory :D thanx again
Topic archived. No new replies allowed.