c**********e 发帖数: 2007 | 1 What are static variable and static function?
What is the difference between static variable and global variable? |
c***g 发帖数: 472 | 2
There are three situations for static
1 static non-local variable/function
2 static local variable
3 static class variable/function (only in C++)
1 static non-local variable is similar to global variable. The difference is
global variable can be accessed by other unit. The static variable can only
be accessed in the same unit.
2 static local variable and static class variable are totally different from
global variable.
【在 c**********e 的大作中提到】 : What are static variable and static function? : What is the difference between static variable and global variable?
|
l*******y 发帖数: 1498 | 3 A static variable is a variable that has been allocated statically — whose
lifetime extends across the entire run of the program.
1. Static global variables are declared as "static" at the top level of a
source file. Such variables are not visible outside the source file ("file
scope"), unlike variables declared as "extern".
2. Static local variables are declared inside a function. They have the same
scope as normal local variables, differing only in "storage duration":
whatever values the funct |
N*******k 发帖数: 43 | 4 我也被问这个问题了。回答得理论了些,说 compilation 啥的,对方不满,说,我关
心的是如何用,什么时候用,做什么用。
【在 c**********e 的大作中提到】 : What are static variable and static function? : What is the difference between static variable and global variable?
|
z****e 发帖数: 2024 | 5 C++:
1. static member function does not have this pointer. So can not access non-
static class members.
2. one doesn't need to instantiates an object to call the static member
function. It only reserves the name scope. |