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 - 3 of 3 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

Give your answer:

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

Answer Question

Click here to Login / Register your free account


 
Send   Reset

 

Related Answered Questions

 

Related Open Questions