472,782 Members | 1,152 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,782 software developers and data experts.

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 1803
<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: James | last post by:
Hello Java NG, I not sure if this is the right NG for this type of question but if not please let me know which is, TIA Any way first off let me say I'm a student and this WAS last weeks lab,...
7
by: BCC | last post by:
Hi, I have a class with several member variables that should be initialized according to user input before an object is instantiated. Using a static variable is required here. But, I would...
9
by: Bryan Parkoff | last post by:
I have noticed that C programmers put static keyword beside global variable and global functions in C source codes. I believe that it is not necessary and it is not the practice in C++. Static...
25
by: Sahil Malik [MVP] | last post by:
So here's a rather simple question. Say in an ASP.NET application, I wish to share common constants as static variables in global.asax (I know there's web.config bla bla .. but lets just say I...
28
by: Dennis | last post by:
I have a function which is called from a loop many times. In that function, I use three variables as counters and for other purposes. I can either use DIM for declaring the variables or Static. ...
5
by: katekukku | last post by:
HI, I need the source code for a programme in C. It should have the basic features of a paint programme like circle, line etc, etc,. I lost a programme which wa driven by keyboard, if somebody...
18
by: Jack | last post by:
Thanks.
9
by: CDMAPoster | last post by:
About a year ago there was a thread about the use of global variables in A97: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/fedc837a5aeb6157 Best Practices by Kang...
12
by: sergey.lukoshkin | last post by:
Hello everyone! My task is in converting numbers from string to int variables. I used istringstream to perform it. So I wrote simple test function. But it doesn't work as I expected because...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.