can anyone tell me the difference between a double variable and static double variable?
can anyone tell me the difference between a double variable and static double variable?
Well, the difference between at static variable and a "norma" variable (if you may) is that a static variable is pushed onto the stack, I believe. So, then the data can be retreived after the return of the function.
1978 Silver Anniversary Corvette
To put it another way a variable holds its value / data from the time the function is entered until the function exits. It has a new value when the function is called again.
A static holds the value / data even after the function has exited and will retain this value until the app exits.
So if you want to 'remember' a value calculated during a function call for use later, declare it as static.
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill
static variables are not usually on the stack. Where in memory they reside is OS dependant but usually the static variables occupy an area under the heap. The stack is normally way above the heap and grows downwards towards it....
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
Oh, I didn't know that. I always thought that it was put on the stack...Originally posted by Stoned_Coder
static variables are not usually on the stack. Where in memory they reside is OS dependant but usually the static variables occupy an area under the heap. The stack is normally way above the heap and grows downwards towards it....
1978 Silver Anniversary Corvette
Stoned Coder is correct.
If you define a variable N in a file as static, then this variable is only known by the functions in that file and cannot be accessed directly by functions defined in other files.
If you define a variable N as static in a function, then that variable is known only in that function and keeps its own value, even when the function exits. When calling the function again, the latest value of N is the current value.