3
Contributors
3
Replies
7
Views
5 Years
Discussion Span
Last Post by deceptikon
1

In the first, the global array is likely to be stored in the BSS (uninitialized data) segment of the executable file itself while the local array is more likely to be drawn from the stack at runtime. Because stack space is already allocated to the executable in one way or another, local variables don't contribute extra bytes to the size of the file.

0

In the first, variable declared is an extern; unless it is assigned a value the memory will not be allocated. In the second,variable is a local to the block and in 'c' execution starts from main() soon after variable is declared; memory space is occupied for 8000 addresses.

0

In the first, variable declared is an extern; unless it is assigned a value the memory will not be allocated.

That's incorrect. Even for variables declared as extern, an object will be linked to it when creating the executable[1], and the object has a size that will contribute to the executable if it's stored in either the data or BSS segment.

In this case linkage is pretty much irrelevant to the question.

[1] Unless there's no actual object, in which case the linker will puke all over your code if you try to use the variable anywhere.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.