Refers to a space where variables and other items may be accessed from any scope.
Questions tagged [global]
4669 questions
59
votes
4 answers
Why are global variables always initialized to '0', but not local variables?
Possible Duplicate:
Why are global and static variables initialized to their default values?
See the code,
#include
int a;
int main(void)
{
int i;
printf("%d %d\n", a, i);
}
Output
0 8683508
Here 'a' is initialized with '0',…

yuvanesh
- 1,093
- 2
- 9
- 19
58
votes
3 answers
Replace all instances of character in string in typescript?
I'm trying to replace all full stops in an email with an x character - for example "my.email@email.com" would become "myxemail@emailxcom". Email is set to a string.
My problem is it's not replacing just full stops, it's replacing every character, so…

Rebecca
- 583
- 1
- 4
- 8
57
votes
3 answers
Why use the global keyword in C#?
I would like to understand why you might want to use the global:: prefix. In the following code, ReSharper is identifying it as redundant, and able to be removed:

Paul Fryer
- 9,268
- 14
- 61
- 93
56
votes
6 answers
Python Django Global Variables
I'm looking for simple but recommended way in Django to store a variable in memory only. When Apache restarts or the Django development server restarts, the variable is reset back to 0. More specifically, I want to count how many times a…

Joe J
- 9,985
- 16
- 68
- 100
55
votes
4 answers
Static global variables in C++
I would like to make an array of integers via the malloc method. I want this array to be global and be used anywhere in my program. I put code in a header file that looked like this:
static int *pieces;
Then I have a function that fills it with…

Christian Daley
- 779
- 2
- 9
- 13
54
votes
1 answer
global variable warning in python
I have a python 2.6 script (yes I know I should upgrade to at least 2.7) that looks like this:
ret_code = 0
def some_func()
global ret_code
...
if __name__ == '__main__':
global ret_code
...
Now I get a warning if I run the…

whomaniac
- 1,258
- 4
- 15
- 22
53
votes
9 answers
The Angular Compiler requires TypeScript >=2.7.2 and <2.8.0 but 2.8.3 was found instead
I starting getting this error on my Angular app:
The Angular Compiler requires TypeScript >=2.7.2 and <2.8.0 but 2.8.3
was found instead
and when I try to downgrade typescript to the right version doing:
npm install -g typescript@2.7.2 it says…

guilhebl
- 8,330
- 10
- 47
- 66
53
votes
4 answers
Python: Why is global needed only on assignment and not on reads?
If a function needs to modify a variable declared in global scope, it need to use the global declaration. However, if the function just needs to read a global variable it can do so without using a global declaration:
X = 10
def foo():
global X
…

Ashwin Nanjappa
- 76,204
- 83
- 211
- 292
52
votes
4 answers
PHP global or $GLOBALS
Is there a best practice / recommendation when I want to use a variable declared outside of a function when it comes to using:
global $myVar
$GLOBALS['myVar']
Thank you.

Francisc
- 77,430
- 63
- 180
- 276
51
votes
7 answers
How to define global functions in PHP
How can I define a global function which would be accessible from any page?

Sussagittikasusa
- 2,525
- 9
- 33
- 47
51
votes
2 answers
Global dictionaries don't need keyword global to modify them?
I wonder why I can change global dictionary without global keyword? Why it's mandatory for other types? Is there any logic behind this?
E.g. code:
#!/usr/bin/env python3
stringvar = "mod"
dictvar = {'key1': 1,
'key2': 2}
def foo():
…

Jovik
- 4,046
- 6
- 24
- 24
50
votes
5 answers
Declaring an ArrayList object as final for use in a constants file
I am generating an ArrayList of objects.
Following is the code
ArrayList someArrayList = new ArrayList();
Public ArrayList getLotOfData()
{
ArrayList someData = new ArrayList();
return someData;
}
someArrayList = eDAO.getLotOfData();
Once I…

Raghu
- 1,141
- 5
- 20
- 39
50
votes
1 answer
Global variables joke
What’s the best naming prefix for a global variable?
//
I saw this joke on the wall in my CS lab and, being fairly inexperienced in C++, didn't get it.
Could someone explain it to me?

Mutantoe
- 703
- 8
- 20
50
votes
4 answers
C++ static local function vs global function
What is the utility of having static functions in a file ?
How are they different from having global functions in a file ?
static int Square(int i)
{
return i * i;
}
vs
int Square(int i)
{
return i * i;
}

Arun
- 3,138
- 4
- 30
- 41
49
votes
4 answers
Changing a global variable from inside a function PHP
I am trying to change a variable that is outside of a function, from within a function. Because if the date that the function is checking is over a certain amount I need it to change the year for the date in the beginning of the code.
$var =…

Chris Bier
- 14,183
- 17
- 67
- 103