Saturday, 26 July 2014

declaration & initialisation of a global & local variable. (linux)

global variable:

In C global variables are stored in data segment ,
if variable is only declared & not initialised with some value :  that variable is stored in BSS(block startup symbol) segment which is starting address of data segment where it is initialised with value '0' with a logical address.When we assign some value to it then it will move to main data segment .
if variable is assigned value at time of declaration : it directly moves to main data segment with some physical addressing.

local variables:

Local variables are stored in stack segment of process context
if variable is only declared & not initialised with some value: logical address is given to the variable like if we initialise "int val" then only 4 bytes or 8bytes (depending on compiler) with starting logical address is given to the variable.But physical addressing is provided by kernel at the time we assign some value to variable.



No comments:

Post a Comment