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;
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.
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.
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
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.
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.