GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Concepts  >  Data Structures
Go To First  |  Previous Question  |  Next Question 
 Data Structures  |  Question 10 of 202    Print  
How is memory reserved using a declaration statement?
Skill/Topic: Variables and Pointers
A) Memory is reserved by using a data type in a declaration statement.
Explanation: The form of a declaration statement varies depending on the programming language you use. For example, here is a declaration statement for C, C++, and Java:int myVariable;



  
Total Answers and Comments: 8 Last Update: March 11, 2008   
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: as_hmr
 
Just to add on.

in C

int i; // it is both declaratoin and defination

extern int i; // this is only declaration

Above answer was rated as good by the following members:
piyushbeli
January 19, 2006 01:34:28   #1  
samiksc Member Since: October 2005   Contribution: 233    

RE: How is memory reserved using a declaration stateme...

Memory is reserved using data type in the variable declaration. A programming language implementation has predefined sizes for its data types.

For example in C# the declaration int i; will reserve 32 bits for variable i.

A pointer declaration reserves memory for the address or the pointer variable but not for the data that it will point to. The memory for the data pointed by a pointer has to be allocated at runtime.

The memory reserved by the compiler for simple variables and for storing pointer address is allocated on the stack while the memory allocated for pointer referenced data at runtime is allocated on the heap.


 
Is this answer useful? Yes | No
April 05, 2006 13:58:28   #2  
Anand Mishra        

RE: How is memory reserved using a declaration stateme...
Memory is reserved at the time of declararion of variable size is dependent on thetype of variable and type of Compiler
 
Is this answer useful? Yes | No
April 24, 2006 01:37:04   #3  
deepak jain        

RE: How is memory reserved using a declaration stateme...
at declaration memory is allocated in case of declaration of variables and not in case ofpointers to some structures.fo that we have to allocate using 'new' keyword.
 
Is this answer useful? Yes | No
November 08, 2006 04:54:54   #4  
Pramod        

RE: How is memory reserved using a declaration stateme...

Memory is not allocated if declare a varialbe merely.

ie

int i; // will not allocate the memory

If we define the variable then only memory will be allocated based on the type of the Data

i 10; // will allocate the memory


 
Is this answer useful? Yes | No
November 26, 2006 23:46:06   #5  
Pradeep Kumar        

@Pramod
Dear Pramod memory is allocated at the time of declaration of the variable.in ur programint i;if you will print this by usingprintf( d i); //it will give some garbage value bcz value of i is not initialisedprintf( u &i); //this is the address of i in memory
 
Is this answer useful? Yes | No
June 29, 2007 01:11:57   #6  
ajitha        

RE: How is memory reserved using a declaration stateme...
First of all u have to understand the difference b/w declaration and definition.
When u define something memory is allocated and when u declare something
memory is not allocated.
int i ;// i is a declaration until the value of i is specified.

 
Is this answer useful? Yes | No
December 28, 2007 05:49:34   #7  
manishmodgil Member Since: July 2006   Contribution: 15    

RE: How is memory reserved using a declaration statement?

In C if we write

int a;

this statement does both viz. declaration and definition. It first created a variable named a and then defines it be of type int and allocated memory. Although we have not specified any data to be stored in the memory allocated the default value is assigned to the varible or junk is there.

But its no that always that a declaration statement reserves memory. If we extend the scope of a variable using extern we are just declaring that the scope is extended and there is no memory allocation or definintion involved.


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
March 11, 2008 09:59:50   #8  
as_hmr Member Since: April 2007   Contribution: 3    

RE: How is memory reserved using a declaration statement?
Just to add on.

in C

int i; // it is both declaratoin and defination

extern int i; // this is only declaration

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape