The difference between static variables (functions) and ordinary variable (function)

Tencent friend saw a side interview subject inside and asked the difference between static and ordinary variables, found that he was not clear, usually also make it much foundation ah. .

Then known as static global variables described earlier (external variables) would constitute a static global variable. Global variables itself is static storage mode, static global variables of course, static storage side style. This is no different in the two storage methods. Although this difference is non-static global variable scope is the whole source, when a source program by a plurality of source files, non-static global variable in each source file is valid. A static global variables are restricted in its scope, that is only valid within the definition of the variable in the source file, the source file in the other of the same source code can not use it in pieces. Due to the limited scope static global variables within a source file, can only function in the source file for the public, so to avoid causing errors in the other source files.

static global variable and a common global variables What is the difference: static global variables are only beginning to make exactly once, to prevent be referred to by a file unit;
static local variables and ordinary local variables What is the difference: static local variables are only initialized once, the once on the basis of a result value;
static function and normal function What is the difference: static function only one in memory, general function to maintain a copy of each call.

Guess you like

Origin www.cnblogs.com/Liu269393/p/10943109.html