GeekInterview.com
Series: Subject: Topic:
Question: 724 of 828

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.
Asked by: Interview Candidate | Asked on: Mar 6th, 2005
Showing Answers 1 - 3 of 3 Answers
gaurav kaushik

Answered On : 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.

  
Login to rate this answer.
Amareswar

Answered On : 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.

  
Login to rate this answer.
kiran

Answered On : 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...

  
Login to rate this answer.

Give your answer:

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

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.