Skip to main content
84 votes
6 answers
69k views

When I use static variables in C++, I often end up wanting to initialize one variable passing another to its constructor. In other words, I want to create static instances that depend on each other. ...
Dimitri C.'s user avatar
  • 22.7k
232 votes
6 answers
235k views

If I have the following code: class Foo(object): bar = 1 def bah(self): print(bar) f = Foo() f.bah() It complains NameError: global name 'bar' is not defined How can I ...
Ross Rogers's user avatar
  • 24.5k
167 votes
2 answers
57k views

How are unnamed namespaces superior to the static keyword?
Sarfaraz Nawaz's user avatar
125 votes
12 answers
394k views

I have searched about static variables in C#, but I am still not getting what its use is. Also, if I try to declare the variable inside the method it will not give me the permission to do this. Why? ...
Kartik Patel's user avatar
  • 9,703
52 votes
5 answers
54k views

For static member variables in C++ class - the initialization is done outside the class. I wonder why? Any logical reasoning/constraint for this? Or is it purely legacy implementation - which the ...
kumar_m_kiran's user avatar
24 votes
6 answers
115k views

What is the difference between a static and instance variable. The following sentence is what I cant get: In certain cases, only one copy of a particular variable should be shared by all objects of ...
user avatar
72 votes
10 answers
69k views

I have concept of static variables but what are the benefits of static methods in a class. I have worked on some projects but I did not make a method static. Whenever I need to call a method of a ...
Naveed's user avatar
  • 42.3k
59 votes
4 answers
47k views

I noticed that if you initialize a static variable in C++ in code, the initialization only runs the first time you run the function. That is cool, but how is that implemented? Does it translate to ...
bobobobo's user avatar
  • 67.9k
25 votes
3 answers
7k views

Why doesn't GCC (4.6.3) give me any warning for the unreachable code in the below example? #include <stdio.h> int status(void) { static int first_time = 1; if (first_time) { ...
Andreas Haas's user avatar
11 votes
4 answers
49k views

In C language, I want to access a global static variable outside the scope of the file. Let me know the best possible way to do it. One of the methods is to assign an extern global variable the value ...
Sikandar's user avatar
  • 357
24 votes
2 answers
14k views

I'm reading a book on Objective-C and the author said that if local variables aren't assigned a value they will be set to nil, but static variables will be set to zero. So, I set up int a and didn't ...
stumped's user avatar
  • 3,315
15 votes
3 answers
49k views

I have three files - global.php, test.php, test1.php Global.php $filename; $filename = "test"; test.php $filename = "myfile.jpg"; echo $filename; test1.php echo $filename; I can read this ...
user2688512's user avatar
6 votes
3 answers
311 views

Can anyone explain to me the reason behind the output of this program to be 0 0 0 0 0? Here we are using a static variable var whose values will not change due to function calls. The values of var ...
C_beginner's user avatar
6 votes
4 answers
6k views

I'd like to do some stuffs before main function. I have multiple source files. In each file, there is some work that needs to be done before main. It was no problem in C++, but problematic with C. In ...
minjang's user avatar
  • 9,090
6 votes
6 answers
70k views

Can we declare Static Variables inside Main method? Because I am getting an error message: Illegal Start of Expression
Priti's user avatar
  • 97

15 30 50 per page
1
2 3 4 5
8