before it is destroyed.2) Local variables are initialized only once, saving memory3) Change scope(2) Modifying global variables1) can only be accessed in this file, modify the scope of global variables, the life cycle does not change2) Avoid repeating the definition of global variables2>extern Effect:(1) is only used to get the value of the global variable, cannot be used to define the variable(2) Working principle is to find in this file there are n
The difference between typedef Define static extern1) #define #definepi 3.1415926In the program: Pi*r*r is replaced with the number in the # define statement 9 g2) A typedef is processed at compile time. It gives an alias to an already existing type within its scope, but you cannot use the typedef specifier inside a function definition.extern can be placed before a variable or function to represent the definition of a variable or function in another file, prompting the compiler to find its defin
1. extern "C" is a keyword in C ++, which is not in C. That is to say, for a pure C compiler, it does not know extern "C" at all, which will lead to compilation errors.
2. extern "C" is used to make C ++ compiled functions and variable names consistent with those after C language compilation, that is, the C and C ++ compatible functions and variables are modif
Global Variables:
Class, outside of the method, the class directly write NSString * str = @ "xxx"; STR is a global variable (object oriented, to use global variables, generally set as properties of the Class)
Local Variables:
Variables written in a method within a class are local variables.
Attention:
const, static, extern is just three variable modifier
const Determines whether a variable can be changed by static to
determine the l
Example:Header file: state.h source file: State.cppOther source files: T1.cpp t2.cpp t3.cpp, these source files contain header file state.h.You need to define a global variable for use in these source files:1. Declare global variables in state.h: extern int A;2. Define the global variable in state.cpp: int a = 10;This allows the variable to be used by other source files.What is needed here is "declaration", not "definition"! According to the C + + sta
In Layman's words:when the extern field is used, the declared variable is a global variable and can be called, as well as a narrower term: extern can extend a variable in one class to another class;Static variables declare variables, variable values after the change, save this change, each time you use to read the value;Const declares that the value of a variable is immutable, is a property of ReadOnly, and
look.
Assembly code:
Well, it is clear here. Here we will explain this: _ zn16sample_namespace10sample_vare
This is generated by the name modification mechanism. This looks unclear, but it can be explained using a tool: C ++ filt _ zn16sample_namespace10sample_vare
The result is simple, but our sample_namespace: sample_var.
Iii. extern "C"
In fact, extern "C" is a keyword that provides
[Abstract] in C language, pointers and arrays are usually used in a similar way. It is also legal to assign values to a pointer variable using an array name. This creates an illusion that arrays are pointers. The difference between them is a common topic. In this article, we will only distinguish between pointers and array access to memory. In addition, we also discuss the issues generated when using pointers as external declarations of arrays, as well as a small difference between
Note In the division operation:If the two digits of the division are integers, then the result is an integer, the fractional part is omitted, such as 8/3 = 2, and two is a decimal , and The result is a decimal number, such as: 9.0/2 = 4.500000.Take note of the remainder operation:This operation is only suitable for two integers , such as: 10%3 = 1, while 10.0%3 is wrong; The post-op symbol depends on the symbol being modulo, such as (-10)%3 =-1; and 10% (-3) = 1.--The storage categories in the C
static and extern use in C + +Both static and extern can be used to modify functions and variables, but there are differences.intrinsic and internal variables: functions and variables that can be used only within a file.External functions and external variables: functions and variables that can be used by other files.Static1 pairs of functionsDefine an intrinsic functionstatic void Test (){}Declares an intr
, external links refers to the program can be different file sharing, internal link refers to only a single file, no link refers to a single function, and can not be shared at all.2. The default storage age, scope, and link of a variable depend on the declaration position of the variable.1) variables declared within blocks: Automatic storage term, block scope, no link.2) variables declared at the outermost part of the program (outside any block): Static storage age, file scope, external link.int
http://blog.csdn.net/cnsword/article/details/8034947Companies can use C++11. See Daniel's code imitation use, so now do not know what the use of C + + syntax or c++11 syntax ... I don't know if it's kind of sad.C++11 has revised the keywords, added nullptr, constexpr, Decltype, default, Static_assert , and the original keywords (auto,using,extern ) meaning and purpose have been revised. Here's a look at the changes to auto, using,
1.C calling a C + + function or variableC calls C + + functions or variables, the header file in C + + is declared as extern "C", and C is called using only the extern declaration.As can be seen, extern "C" tells the C + + compiler to use the C link rule to generate and find the symbol name in the target file.In short, the ex
iOS variables are pre-added with extern and static fieldsA while ago, to do the project time to find the online demo, open run when found in the variables before the keyword extern and static, so I studied a suddenFor extern, it can be understood as an extension. This is the extension from one class to another.Defining a variable in SPLASHVIEWCONTROLLER.M is like
This is about the link property of the identifier, there are only three link properties: External,Internal, none changes the rule:3.1file scope variables and function definitions, that is, identifiers outside of all code blocks and parameter lists, with static adornments, have internal link properties. Cannot add static before function declaration3.2an identifier is declared as extern, and the same identifier has been declared before, (that is, the pr
Static:1. modifying local variables , modifying local variables by static, extending the life cycle , related to the entire application * modified by static local variable , only once memory is allocated * modified by static local variables what allocates memory ? when the program runs, it allocates memory to the static modifier variable .2. Modify Global Variables , be static modified global variables , scope will be modified , can only be used under the current file
What does extern mean?
A:The extern modifier is used to declare member functions implemented outside the Assembly and is often used to call system API functions (through DllImport ). Note: static modifiers must be added for use with DllImport. They can also be used for calls to components of different versions of the same assembly (alias declaration using extern)
accessed, but I do not want to let other files access, this can be used to decorate it with the static keyword, the more typical use is GCD one-time function created by the Singleton, the global variable will basically use static decoration.Here is a singleton created using the GCD disposable function@implementation Logintool // static modifies global variables so that external files cannot be accessed Static Logintool *_sharedmanager = nil; + (Logintool *) sharedmanager { static dispatch
are also variables stored in CPU Register, or stored in the cache, as much as the block is accessed and manipulated, because a register variable exists in the register rather than in memory, all cannot get the address of the register variable, but in other respects, the register variable and the automatic variable, that is, They all have code block scopes, empty joins, and automatic storage periods, and register variables can be represented by Register . 3 Global variables (static external
Original: The role of the keyword auto, static, register, const, volatile, extern in C languageKeyword auto, static, register, const, volatile, externThese keywords are basic knowledge of C + +, I have organized a bit, I hope to be useful to the newly-learned friends:(1) AutoThis keyword is used to declare that the lifetime of a variable is automatic, and that variables defined in any class, struct, enumeration, union, and function are not treated as
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.