Categorii: Tot - variables - address - scope - value

realizată de Levi George 3 ani în urmă

223

Chapter 5: Names, Bindings, and Scopes

The section delves into the intricacies of variable management in programming, focusing on the concepts of scope and lifetime. Scope defines the reachability of a variable, indicating where it can be accessed within the code.

Chapter 5: Names, Bindings, and Scopes

Chapter 5: Names, Bindings, and Scopes

5.6: Scope and Lifetime of Variables

Both of these concepts become fuzzy with subprogram calls and in a number of other situations outside of function calls from main.
C++'s 'static' keyword extends lifetime beyond the life of the function, but doesn't alter scope.
Scope is where the function can be reached, Lifetime is temporal and is the time that the memory for that variable exists and is allocated
Often restricted to the function range
Scope is the "reach" that a variable has, where it may be accessed.

5.3: Variables int varName = varValue

Type
The type of information stored, this in part determines the amount of memory and how that information is stored. A long int will take up more space than a short or regular int. (The type in this case is int, it precedes the variable name. In some cases it is not needed)
Address
Addresses are the computer memory cells that store information in them regarding the variable. This is not seen directly by programmers.
Name
Names are the way that we identify variables. Immediately after type (varName in this case)

Aliases

One address can be referenced by two names, not good for reading code

Value
That which is stored within a variables memory. placed on the RHS of a declaration or assignment.