First up, the two things are: static, and variable.
We will describe the functions as; static functions, and normal functions.
We will describe the records of data as; static fields, and normal / variable fields.
For classes, we will describe as, static classes, and normal classes.
A static field is one where the value of the variable will/does not change after setting it initially.
A normal / variable field can take on any value of it type, eg, int, char, etc.
Basically, one use of a static field would be to keep the value of 'pi'. As this value does not change, a static field would be best used.
Whereas, using a counter inside a loop does change, and it would use a normal / variable field.
A static function, means that no internal field (static or normal) inside the class, struct, etc, will not change as a result of a call to this function. Does not stop fields inside the function from being changed / variable.
A normal function may change the internal fields inside the class, struct, etc. If you had a data structure that held a number and a count of the times this number has been seen, if you called an increment function, it would change the internal counter, and could not be a static function.
A static class only has static functions.
A normal class can have both static and normal functions.
Another thing is, anything static will usually only occupy one space in memory during the execution of a program.
2006-09-27 17:08:35
·
answer #1
·
answered by Mark aka jack573 7
·
0⤊
0⤋
The 'static' key-word is one in each and every of those C compiler directives that are particularly stupid and redundant. i will start up off by skill of explaining the adaptation between worldwide and domestically disbursed records. once you create a variable interior significant(), the information is disbursed off this technique stack. The stack is nearly a factor of memory that the CPU and your software makes use of. case in point, in case you allocate an unsigned integer in significant(), the compiler creates code to allocate th variable on the stack, and whilst significant exits, it has bumped off. an identical factor occurs in case you allocate a variable in a technique. worldwide variables are disbursed from this technique's records area. in case you create an initialized variable exterior of significant(), then that variable is assigned a memory handle and the linked fee is quite saved on your .exe record, and then loaded into the information area whilst your software a lot. despite if that's an uninitialized variable, then no longer something is saved interior the .exe record, however the compiler has assigned the variable a memory handle. utilising the 'static' key-word once you allocate a variable in a technique (which contain significant()), tells the compiler to gather the variable as a worldwide variable. See? I informed you that 'static' replace right into a redundant compiler directive. occasion: static unsigned int phooey;
2016-12-12 16:30:55
·
answer #2
·
answered by hirschfeld 4
·
0⤊
0⤋
one declared they are available throughout the entire program. A reason they could be needed is what is you needed to access a variable or function thought out your program and didn't want to pass the variable by reference or value?
2006-09-27 16:49:51
·
answer #3
·
answered by D 4
·
0⤊
0⤋