IT Community - Software Programming, Web Development and Technical Support

Static Global Variable and Static Local Variable

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?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C and C++ Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 05-18-2007, 04:18 AM
vigneshgets vigneshgets is offline
D-Web Genius
 
Join Date: Mar 2007
Posts: 904
vigneshgets is on a distinguished road
Exclamation Static Global Variable and Static Local Variable

Hi Guys can you tell me how can you define the Static Global Variable and Static Local Variable?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-30-2007, 11:50 AM
shanmugamit shanmugamit is offline
D-Web Trainee
 
Join Date: Mar 2007
Posts: 10
shanmugamit is on a distinguished road
Default Re: Static Global Variable and Static Local Variable

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;
}
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -7. The time now is 08:06 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0