2. c ++ primer 4 th notes, basic language-related concepts [1]

Source: Internet
Author: User

1. In C ++, each expression produces a result, which usually applies the operator to the value produced by its operand. When the operator is an output operator, the result is the value of the left operand. That is to say, the value returned by the output operation is the output stream itself.

2. annotation pairs cannot be nested. /**/

3. When we use the istream object as the while test condition,The result is the test stream status.If the stream is valid (the input is a valid character or does not reach the end of the file), the test is successful.

4. Because the header file uses angle brackets to find the header file, it is first found under the system directory, and double quotation marks are found under the directory where the project is located, so generally, the header file of the standard library uses angle brackets, and the non-standard library uses double brackets.

5. By default, read CIN refresh the cout.ProgramCout will also be refreshed when it ends normally.

6. C ++ is a static type language that performs a type check during compilation.

7. In C ++, it is completely legal to assign a negative value to an unsigned object. The result is the value after this negative number is calculated for the number of values of this type.

8. The variable type determines the memory size and layout of the variable, the value range of the value that can be stored in the memory, and the operation set that can be applied to the variable.

9. The left value can appear on the left or right side of the value assignment statement. For example, the variable is the left value. The right value can only appear on the right side of the value assignment statement. For example, the logarithm is the right value, and the right value can only be read or written.

10. Generally, an object is a type area in the memory.

11. Initialization is not a value assignment. Initialization is to create a variable and give the initial value, while the value assignment is to erase the current value of the object and replace the new value.

In terms of concept, the assignment operation should do the following:

For example, S1 = S2

1) first release the memory occupied by S1;

2) then allocate S1 enough memory space to store S2 copies;

3) Finally, copy all characters in S2 to the allocated memory space.

12,The definition of a variable is used to allocate storage space for the variable. You can also specify the initial value. In a program, the variable has only one definition.

Declaration is used to indicate the type and name of the variable to the program, and the definition is also declaration. The statement can be made multiple times.

Only when the declaration is defined can the Declaration have an initialization type, and only when the extern declaration is outside the function can the initialization type be included.

12. The default non-const variable is extern. To make the const variable accessible in other files, you must explicitly specify it as extern.

13. composite types refer to types defined by other types. The reference type cannot be defined.

14. const reference refers to the reference of the const object.

15. A non-const reference can only be bound to an object of the same type as the reference. A const reference can be bound to an object of different but related types or to the right value.

16. Enumeration members are constant expressions. Constant expressions are integer expressions that can be computed by the compiler during compilation.

17. The const object is the local variable of the file that defines it by default. After we define the const variable in the header file, each source file containing the header file has its own const variable, with the same name and value.

18. The Escape Character is followed by a backslash, a three-digit octal number or a hexadecimal number.

19. To avoid overflow, the safest way to save the size of a string object is to use the standard library type string: size_type; which is defined to have the same meaning as unsigned. But do not assign the returned result of size to an int variable.

20. String and literal value connections

When the string object and the string literal value are joined together, at least one of the left and right operands of the + operator must be of the string type.

21. A vector is a class template. The data type is only available, such as a vector <int>.

Only existing elements can be indexed using subscript operations. When values are assigned through subscript operations, no elements are added.

22. iterator

Vector <int>: const_iterator // an iterator that cannot write Elements

Const vector <int>: iterator // an iterator whose value cannot change

Any operation that changes the length of a vector will invalidate the existing iterator. For example, after push_back is called, you cannot trust the previous iterator pointing to the vector.

Difference_typeThe signed integer defined by vector is used to store the distance between two iterators.

23. bitset

The bitset class is also a type template, which is initialized by length. Such as bitset <32>.

You can use the unsigned value to initialize a bitset object, which is aligned with a low level bit. You can also initialize the bitset object of the string object. The String object and the bitset object are converted in reverse order: the rightmost character of the string object (the character with the largest subscript) it is used to initialize the low-level bits of a bitset object (that is, the bits of subscript 0 ).

String strval ("1000 ");

Bitset <32> bitvec4 (strval);

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.