468,103 Members | 1,318 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,103 developers. It's quick & easy.

Info on Static Variables Needed by SHIKHAR

HI,
Could anyone please tell me what are static variables and what exactly
are there features.
I am a little bit confused.

Thank You

Jul 23 '05 #1
2 1632
<ka*******@yahoo.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
HI,
Could anyone please tell me what are static variables and what exactly
are there features.
I am a little bit confused.


Object names qualified with the keyword 'static'
are give 'static storage duration', that is, they
have a lifetime equal to that of the program's
execution. 'static' objects are also default-
initialized if no explicit initial value is
given.

Which C++ book(s) are you reading which don't
explain this?

-Mike
Jul 23 '05 #2
On 8 Jun 2005 11:32:57 -0700, ka*******@yahoo.com wrote:
HI,
Could anyone please tell me what are static variables and what exactly
are there features.
I am a little bit confused.


There are static member variables, local static variables inside a
function definition, and global static variables at file scope.

In a nutshell, storage for static member variables is allocated
independently of any object of the class of which they are a member.
They must be initialized outside of the class definition (i.e. at
global scope).

Inside the body of a function definition, storage for a static
variable is allocated before the program runs. The value of such a
variable remains persistent beyond the scope of the function being
called. The initialization of such function static variables is done
before the function is called the first time -- sometimes well before,
but sometimes only at the last moment. I believe this is
implementation defined (please someone correct me if I'm mistaken,
don't have time right now to look it up...).

Variables declared globally outside a class or function body with the
keyword "static" are only visible at file scope in the translation
unit in which they are defined. IOW, you can have multiple variables
with the same name if they are all declared with the keyword "static"
and there is only one per translation unit.

--
Bob Hairgrove
No**********@Home.com
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by James | last post: by
7 posts views Thread by BCC | last post: by
9 posts views Thread by Bryan Parkoff | last post: by
25 posts views Thread by Sahil Malik [MVP] | last post: by
5 posts views Thread by katekukku | last post: by
18 posts views Thread by Jack | last post: by
12 posts views Thread by sergey.lukoshkin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.