Memory allocation in C

1 view
Skip to first unread message

ArunPr...@gmail.com

unread,
Dec 30, 2004, 7:20:46 AM12/30/04
to CppF...@googlegroups.com
In C programming language when I declare a variable

int i, j;

when will the allocation happen.. ie. During the execution of this
instruction or when the variable is first used.
Please clarify...

Thanks in advance

Venkatesh Raja

unread,
Jan 6, 2005, 7:56:49 AM1/6/05
to CppF...@googlegroups.com
The C language supports two kinds of memory allocation through the
variables in C programs:

* Static allocation is what happens when you declare a static or
global variable. Each static or global variable defines one block of
space, of a fixed size. The space is allocated once, when your program
is started (part of the exec operation), and is never freed.

ie. once u declare any primitive type.. memory will be
allocated for that variable.

* Automatic allocation happens when you declare an automatic
variable, such as a function argument or a local variable. The space
for an automatic variable is allocated when the compound statement
containing the declaration is entered, and is freed when that compound
statement is exited.

In GNU C, the size of the automatic storage can be an expression
that varies. In other C implementations, it must be a constant.

I hope this helps you...


******><><><><><><********
A born Programmer
******><><><><><><********
--


***************** Use I.T, Dont get used to I.T ******************
Venkatesan. R
Reply all
Reply to author
Forward
0 new messages