This is a discussion on Static Global Variable and Static Local Variable within the C and C++ Programming forums, part of the Software Development category; Hi Guys can you tell me how can you define the Static Global Variable and Static Local Variable?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| A static variable can be either a global or local variable. Both are created by preceding the variable declaration with the keyword static. A local static variable is a variable that can maintain its value from one function call to another and it will exist until the program ends. When a local static variable is created, it should be assigned an initial value. If it's not, the value will default to 0.The following example sets a static local, called TheLocal, to the value 1000. void main(void){ static stort TheLocal; /* a static local variable*/ TheLocal=1000; } A global static variable is one that can only be accessed in the file where it is created. This variable is said to have file scope The following example also sets a global, called TheGlobal, to the value 1000 static short TheGlobal; /* a static global variable*/ void main(void){ TheGlobal=1000; } |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Static members | ragavraj | PHP Programming | 2 | 12-06-2007 08:17 PM |
| How to define a global variable in PHP? | itbarota | PHP Programming | 3 | 11-01-2007 10:58 AM |
| static variable in a method | connect2sathya | Java Programming | 4 | 07-18-2007 10:49 PM |
| difference between a static and a non-static inner class | vigneshgets | Java Programming | 1 | 05-23-2007 11:02 PM |
| Java Static | swoosh | Java Programming | 3 | 05-08-2007 04:36 AM |