The annotation of <C ++ primer> {fujiwon bean curd shop user}, annotationprimer
The annotation of <C ++ primer>
{Fujiwon bean curd square for home use}
An initial value for a variable name is almost always correct, but this is not required.
One of the main design goals of C ++ is to allow programmers to customize types, which are as easy to use as built-in types.
What is an object?
Generally, an object is a zone of type in the memory. To be specific, an object is generated when the left expression is calculated.
About Initialization
C ++ supports two initialization methods,
Copy initialization
Directly initialize direct-initialization
Int ival (123); // direct-initialization
Int ival = 123; // copy-initialization
Initialization is not a value assignment!
C ++ emphasizes that assignment and initialization are not the same !!
Initialization refers to creating a variable and assigning it an initial value, while assigning a value is to erase the current value of the object and replace it with a new value.
Definition of the left and right values.
1. lvalue (pronounced "ell-value"): An expression that is an lvalue may appear as either
Left-hand or right-hand side of an assignment.
2. rvalue (pronounced "are-value"): An expression that is an rvalue may appear on the right-
But not left-hand side of an assignment.
Variable initialization rules:
Initialization of Variables of Built-in Type
Whether a variable of built-in type is automatically initialized depends on where it is defined. variables defined outside any function body are initialized to zero. variables of built-in type defined inside the body of a function are uninitialized. using an uninitialized variable for anything other than as the left-hand operand of an assignment is undefined.
Initialization of Variables of Class Type
Each class may also define what happens if a variable of the type is defined but an initializer is not provided. A class does so by defining a special constructor, known as the default constructor. this constructor is called the default constructor because it is run "by default;" if there is no initializer, then this constructor is used. the default constructor is used regardless of where a variable is defined.
Note! The extern declaration is neither a definition nor a bucket. In fact, it only indicates that the variable is defined elsewhere in the program. In the program, the variable can be declared multiple times, but can only be defined once.
What is scope )?
The context used to distinguish different meanings of names is called scope.
(You can always express a very emotional concept in a simple way, Ah worship lippman)
Generally, the local scope and global scope are very familiar to C programmers. here we need to emphasize the statement scope ).
For (int val = 1; val <10; val ++)
Here, the val variable is the variable in the scope of a statement. It is defined in the scope of the for statement and can only be used in the for statement, but not in the main function.
Some Questions about const will be posted and sorted out in a centralized manner. I have encountered all questions about const :)
Reference:
A reference is another name of an object. A reference of the reference type cannot be defined, but any reference of other types can be defined. (secondary reference is not allowed)
int ival = 1024;int &refVal = ival; // ok: refVal refers to ivalint &refVal2; // error: a reference must be initializedint &refVal3 = 10; // error: initializer must be an object
Initialization is the only method that specifies the object to which the reference is directed.
A const reference is a reference to a const object.
This behavior is easiest to understand when we look at what happens when we bind a reference to an object of a different type. If we write
double dval = 3.14;const int &ri = dval;
The compiler transforms this code into something like this:
int temp = dval; // create temporary int from the doubleconst int &ri = temp; // bind ri to that temporary
What is the role of typedef?
- To hide the implementation of a given type and emphasize instead the purpose for which the type is used
- To streamline complex type definitions, making them easier to understand
- To allow a single type to be used for more than one purpose while making the purpose clear each time the type is used
Each sentence member is a constant. the enumerated member value cannot be changed. an enumerated member is a constant expression, so it can be used anywhere where a constant expression is needed. each enum defines a unique type. the initialization or assignment of an enumerated object can only be performed by its enumerated members or other objects of the same enumerated type.
Data member of the class:
There are important differences between defining variables and defining data members:
Generally, Class Members cannot be initialized as part of their definition. when defining a data member, you can only specify the name and type of the data member. the class does not initialize the data member when defining the data member in the class definition, but controls the initialization through the special member function of the constructor.
Access ID:
The access label controls whether the code using this class can use a given Member. the member functions of a class can use any member of the class regardless of its access level. the access label is public and private can appear in the class definition multiple times. The given access label is applied until the next access label appears.
The only difference between defining a class with the class and struct keywords is the default access level: by default, the struct member is public, and the class member is private.
Incomplete ~ To be updated
February 2015 shot in Hunan
Sakura (O) O ~ next to a primary school Road ~ It should be cherry blossom )~