Hello,
Static variables are stored in initialised rw memory in the process memory area. Can anyone tell me what does the OS does internally in order to save its contents, if the variable is defined and used inside a function and called twice?
suresh
Hello,
Static variables are stored in initialised rw memory in the process memory area. Can anyone tell me what does the OS does internally in order to save its contents, if the variable is defined and used inside a function and called twice?
suresh
Here is a good page that answers all your questions:
http://www.purdue.edu/PUCC/Short-Cou...s/p_00200.html
Cheers,
Z.
Beware the fury of a patient man.
What do you mean by this??Can anyone tell me what does the OS does internally in order to save its contents, if the variable is defined and used inside a function and called twice?
Saravanan.T.S.
Beginner.
>Can anyone tell me what does the OS does internally in order to save its
>contents, if the variable is defined and used inside a function and called twice?
Local variables exist on the stack. They're pushed onto the stack when the function is entered and popped off the stack when the function exits. static variables are stored in the data segment of your executable. Since they aren't stored on the stack, and thus not created and destroyed at runtime, the memory exists throughout the program's execution. That's why static variables save their contents between function calls.
My best code is written with the delete key.
Perfect, but in which part of data segment does it exits, does it exists in initialised read/write memory as even if you dont initialize a static variable , it gets zero value?
Yes it is stored in intialized data area and those variables are intialized to zero implicitly.
Saravanan.T.S.
Beginner.