The annotation of <<c++ primer>> {Fujiwara tofu square home Use}

Source: Internet
Author: User

The annotation of <<c++ primer>>

{Fujiwara Tofu square home Use}




Giving a variable name an initial value is almost always correct. But it's 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?

In general, an object is an area of the type in memory that is specific, and an lvalue expression is evaluated to produce an object.


About initialization

C + + supports two types of initialization,

Copy Initialize copy initialization

Direct initialization of 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 operation!!

Initialization refers to creating a variable and assigning it an initial value, while the assignment is to erase the object's current value and replace it with a new value.


Definition of Lvalue right value.

1. Lvalue (pronounced "ell-value"): An expression, which is a lvalue may appear as either the
Left-Hand or right-hand side of an assignment.


2. Rvalue (pronounced "are-value"): An expression, which is a rvalue may appear on the right-
But isn't left-hand side of an assignment.

Rules about the initialization of variables:

Initialization of Variables of built-in Type


Whether A variable of built-in type is automatically initialized depends in where it is defined. Variables defined outside any function body is initialized to zero. Variables of built-in type defined inside the body of a function is uninitialized. Using a uninitialized variable for anything other than as the left-hand operand of a assignment is undefined.


Initialization of Variables of Class Type

Each of the classes may also define what happens if a variable of the type are defined but an initializer are not provided. A class does so by defining a special constructor, known as the default constructor. This constructor was called the default constructor because it is run ' by default; ' If there is no initializer and then this C Onstructor is used. The default constructor is used regardless of where a variable is defined.



Attention! The extern declaration is not a definition, nor does it allocate storage space. In fact, he just explained that variables are defined elsewhere in the program, and variables can be declared more than once, but only once.


What is scope (scope)?

The context used to distinguish the different meanings of a name is called a scope.

(Daniel can always put a very emotional concept is very concrete and superficial expression, Ah worship Lippman)


General local scopes and global scopes are familiar to C programmers. It is important to highlight the statement scope (statement scope).

for (int val = 1; val<; val++)

Here the Val variable is a variable within the scope of the statement. It is defined in the scope of the For statement and is used only in the For statement, not in the main function.


Some questions about const will be put on a stick. I've met all the questions about const:)




Reference:

A reference is another name of the object. You cannot define references of reference types, but you can define any other type of reference. (cannot be quoted two times)

int ival = 1024;int &refval = ival; Ok:refval refers to Ivalint &refVal2; ERROR:A reference must be initializedint  &refval3 = ten;//Error:initializer must is an object

Initialization is the only way to indicate which object the reference points to.

A const reference is a reference to a const object.


This behavior was easiest to understand if we look at what happens when we bind a reference to an object of a different t Ype. If We write

Double dval = 3.14;const int &ri = Dval;


The compiler transforms this code to something like this:

int temp = Dval;  Create temporary int from the doubleconst int &ri = temp;  


Classmate, would you please tell me about 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 value of an enumeration member cannot be changed. An enumeration member is itself a constant expression, so it can also be used anywhere that a constant expression is required. Each enum defines a unique type. Initialization or assignment of an object of an enumeration type can only be done by its enumeration members or by other objects of the same enumeration type.



Data members of the class:

There are very important differences in defining variables and defining data members:

the initialization of a class member cannot generally be used as part of its definition. When you define a data member, you can specify only the name and type of the data member. A class does not initialize a data member when it is defined in a class definition, but instead controls initialization by a special member function of the constructor.


Access designator:

The access designator is responsible for controlling whether the code using the class can use the given member. A member function of a class can use any member of a class regardless of its access level. Access label public, private can appear more than once in the class definition, given the access designator applied to the next access label appears.


The only difference between defining classes with class and struct keywords is the default access level: By default, struct members are public and class members are private.






Not finished ~ Pending update






February 2015 in Hunan

The Cherry Blossoms (O (∩_∩) o~ at the side of a primary school should be cherry blossom bar) ~








The annotation of <<c++ primer>> {Fujiwara tofu square home Use}

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.