What is static memory allocation and dynamic memory allocation? 

 Static memory allocation: The compiler allocates the required memory space for a declared variable.By using the address of operator,the reserved address is obtained and this address may be assigned to a pointer variable.Since most of the declared variable have static memory,this way of assigning pointer value to a pointer variable is known as static memory allocation. memory is assigned during compilation time.Dynamic memory allocation: It uses functions such as malloc( ) or calloc( ) to get memory dynamically.If these functions are used to get memory dynamically and the values returned by these functions are assingned to pointer variables, such assignments are known as dynamic memory allocation.memory is assined during run time.

Showing Answers 1 - 16 of 16 Answers

gaurav kaushik

  • Oct 26th, 2006
 

in static memory allocation memory is assigned at compile timefor ex int arr[] = {1,2,3};compiler will allocate memory for 3 integer at compile.whil in dynamic memory allocation memory is assigned at run time. ex malloc(20)compiler will simply see its a function and is argument.while th memory will be allocated at run time.

  Was this answer useful?  Yes

Amareswar

  • Dec 1st, 2006
 

Static memory is pre-allocated during process mapping into the main memory.

Dynamic memory is allocated on heap space of the process map. Visibility throughout the process with the help of a pointer reference.

  Was this answer useful?  Yes

kiran

  • Apr 26th, 2007
 

main()
{
if(true)

{
int a;
int b;
}
else
{
int c;
int d;
}
getch();
}
here in the above program, memory is allocated at compaliation time .since the size of above program is 4*2=8 bytes...

main()
{
if(true)
{
int a=new int;
int b=new int;
}
else
{
int c=new int;
int d=new int;
}
getch();
}
here in the above progame, memory allocated at dynamically(at run time).since the size of the above progam is 2*2=4bytes...

  Was this answer useful?  Yes

divanshu

  • Mar 21st, 2015
 

But pointer is not used as per in dynamic memory allocation

  Was this answer useful?  Yes

As of the 2011 standard (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf), C has four storage durations for objects: static, thread, automatic, and allocated (6.2,4 Storage Durations of objects). Objects with static storage duration are allocated and initialized at program startup and released at program exit. Objects with thread storage duration are created when their enclosing thread is created and exist for the lifetime of the thread. Objects with automatic storage duration exist for the lifetime of their enclosing block. Allocated objects are created with a call to malloc, calloc, or realloc, and exist until explicitly deallocated with a call to free.

  Was this answer useful?  Yes

An array created at compile time by specifying size in the source code has a fixed size and cannot be altered at run time. The process of allocationg memory at compile time is known as STATIC MEMORY ALLOCATION and the arrays that recieve static memory alloaction are called STATIC ARRAYS. This approach works fine as long as we know exactly what our data requirements are.
It is possible to allocate memory to arrays at run time. This feature is known as DYNAMIC MEMORY ALLOCATION and arrays created at run time are called DYNAMIC ARRAYS.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions