#1
  1. No Profile Picture
    SpeedyDan
    Guest
    Devshed Newbie (0 - 499 posts)
    if i call a function and use a variable in it, will it still be set the next time i call the function or not. if not, how can i achieve that. do i have to define a global?

    ------------------
    See ya and thanks

    &Dan
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Location
    Alkmaar, The Netherlands
    Posts
    123
    Rep Power
    15
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR> do i have to define a global?[/quote]

    Yes! Function variables are intended to only be used inside that function during the functions execution. When the function is finished the variable gets out of scope and its memory is freed. If you want to keep the result you thus have to define a global variable.



    ------------------
    Good luck,
    Bas

    ------------------
    E-mail me at: b.vandermeijden@pecoma.nl
  4. #3
  5. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Global is one way. However, if you aren't using the variable outside of the function, (or using it in a different context), think about using STATIC instead.

Similar Threads

  1. Replies: 2
    Last Post: February 11th, 2004, 12:03 AM
  2. problem with functions
    By veni123 in forum C Programming
    Replies: 8
    Last Post: February 5th, 2004, 03:22 PM
  3. functions and the passing of variables
    By keef0r in forum HTML Programming
    Replies: 1
    Last Post: January 25th, 2004, 03:42 PM
  4. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 2
    Last Post: January 9th, 2004, 03:26 PM
  5. Replies: 2
    Last Post: November 3rd, 2003, 02:20 PM

IMN logo majestic logo threadwatch logo seochat tools logo