static variable

4 replies [Last post]
dhanunjaya
Offline
Last seen: 9 years 33 weeks ago
Joined: 2009-04-26
bOt Points: 153

bOtskOOl
Offline
Last seen: 9 years 31 weeks ago
Joined: 2009-02-21
bOt Points: 3500
Re: static variable

A variable that retains the same data throughout the execution of a program

 is called static variable. eg -

static int = 5;

dhanunjaya
Offline
Last seen: 9 years 33 weeks ago
Joined: 2009-04-26
bOt Points: 153
static variables

where static variables are stored in memory

shotgun
Offline
Last seen: 10 years 21 weeks ago
Joined: 2009-03-20
bOt Points: 122
static variable!

Static variables are stored in data segment of memory...........I guess!!

codeguru
Offline
Last seen: 10 years 21 weeks ago
Joined: 2009-04-08
bOt Points: 114
@shubham

@shotgun

you are near to the exact answer .

 

 

 

basically the memory available to a program has two parts

·         :: Data Segment (Data + BSS + Heap)

·         :: Stack

 

 

·         The Data area contains global variables used by the program that are not initialized to zero. For instance the string defined by char s[] = "hello world"; in C would exist in the data part.

·         The BSS segment starts at the end of the data segment and contains all global variables that are initialized to zero. For instance a variable declared static int i; would be contained in the BSS segment.

·         The heap area begins at the end of the BSS segment segment and grows to larger addresses from there. The Heap area is managed by malloc, realloc, and free, which use the brk and sbrk system calls to adjust its size. The Heap area is shared by all shared libraries and dynamic load modules in a process.

·         The stack is a LIFO structure, typically located in the higher parts of memory. It usually "grows down" with every register, immediate value or stack frame being added to it. A stack frame consists at minimum of a return address.

 

to sum up

 

global variables-- data

static variables--BSS

auto variables(which are not global)--stack