| |
GeekInterview.com > Interview Questions > Programming > C
| Print | |
Question: Garbage Value
Answer: In C if a variable is not assigned a value then why does it take garbage value?
|
| March 03, 2009 15:07:46 |
#2 |
| mihir_void |
Member Since: March 2009 Total Comments: 3 |
RE: Garbage Value |
| This happens only in case of local varibales. As memory for local variables are allocated on stack and while allocating the memory the runtime system does not clear the memory before allocating it to the variable unlike in case of allocating memory in heap for global and static variables. Hence the default value of local varibles beomes the content of its memory on stack while that of constant and static variables is 0. |
| |
Back To Question | |