![]() |
|
#1
|
|||
|
|||
Life Time of Function static variable?I would like to discuss something about a static variable in a function body.
CPP / C++ / C Code:
Ok here's my question. Since static variable is valid through the whole life time of the program in the function body. Since i reference the static variable through the function call, can i change the value of the static variable outside the function body?? |
|
#2
|
|||
|
|||
Re: Life Time of Function static variable?Quote:
Very bad style, but shows that it can be done: CPP / C++ / C Code:
|
|
#3
|
|||
|
|||
Re: Life Time of Function static variable?Quote:
When i does programming, i'll try not to use globals if i can as its also a good programming practice. From my point of view, it depends on applications that you are developing. Don't worry, this is just a discussion not a argument or what. Just to share some of my findings........ |
|
#4
|
|||
|
|||
Re: Life Time of Function static variable?btw. in my previous example I forgot to write the "return 0;" to the main function.
anyways .. using globals is not always a bad idea. It can be very good indeed for storing information which you will need in many functions. When some newbie programmers tend to declare everything as a global variable regardless of where the variable is going to be needed then yes we give the advice that try to avoid global variables. The declaration place of the variable determines the scope of the variable and when you plan/write your program you must invest some tought to the question "where am i going to use and access this information". Answer to that question gives you the scope where to put the variable declaration |
Recent GIDBlog
Writing a book by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| triangle (polygon), drawing, sizing, and rotation programme using linked lists... | promsan | C Programming Language | 12 | 14-May-2007 14:03 |
| constructors/classes | mapes479 | C++ Forum | 3 | 19-Nov-2006 17:34 |
| Handling keyup events. | harroldm | FLTK Forum | 3 | 24-Aug-2006 08:48 |
| Revising Script style ?????? | pepee | MySQL / PHP Forum | 4 | 14-Apr-2004 04:59 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The