Thread: the diffrence between static double and double

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    4

    the diffrence between static double and double

    can anyone tell me the difference between a double variable and static double variable?

  2. #2
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    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

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    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

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    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

  5. #5
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    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....
    Oh, I didn't know that. I always thought that it was put on the stack...
    1978 Silver Anniversary Corvette

  6. #6
    Sayeh
    Guest
    Stoned Coder is correct.

  7. #7
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Copying 2-d arrays
    By Holtzy in forum C++ Programming
    Replies: 11
    Last Post: 03-14-2008, 03:44 PM
  2. C++ to C Conversion
    By dicon in forum C Programming
    Replies: 7
    Last Post: 06-11-2007, 08:38 PM
  3. need some help with last part of arrays
    By Lince in forum C Programming
    Replies: 3
    Last Post: 11-18-2006, 09:13 AM
  4. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  5. Unknown Math Issues.
    By Sir Andus in forum C++ Programming
    Replies: 1
    Last Post: 03-06-2006, 06:54 PM