"C ++ Primer Third Edition" Reading Notes - Chapter 3 C ++ Data Types

zhaozj2021-02-16  88

1, text constant

0 can be added to 0 before the integer text constant, represents the number of eight-based, plus 0x represents the number of hexadecimal numbers, such as 0x14 represents a decimal 20. After the integer text constant can be added to L (or L, but recommended by uppercase letters, not easy and digital confusion) represents the long type, plus U (or U) means unsigned number, such as 1024UL. In scientific counting, the index can be written as E or E, such as 3E-3 representation 3 × 10-3. Floating-point text constants are default to Double type, which can be added to f or f to represent single-precision text constants; the extended accuracy is indicated by rear heel L or L. Character text plus l represents wide character text, type Wchar_t. Adding / indicated in the string continues in the next line. The string is before adding to representing the width string text to end with a wide empty character. Two (width) strings are adjacent to the program, C will connect them together and add an empty character, such as "Two" "Some", the result is "twosome".

2, do not use undefined program characteristics, such programs are unmiglable, and error is not easy to find.

3, complex technical solutions generally begin a lot of time, and the processing process is easier, but in these wrong processes, not only do things can be completed, but also expand the imagination space, full of fun.

4, each object can only be defined once, but can declare multiple times.

5, object's naming

Generally written letters such as Index. INDEX typically defines the pre-processor indicator #define. Index is generally used as a type name. Indicates the name of the help letter. Such as Table or TBL. For the identifier consisting of multiple words, it is generally added to each word (there is a C or a process of processing background), or the first word of each word embedded (with object-oriented background) People like it).

6. If a variable is defined within a global scope, the system guarantees that the initial value is 0; if it is defined within the local domain, or dynamically allocated through the New, then they It is uninitialized, the value is undefined (undefined, a random bit string may be the result of previous use).

7, each built-in data type supports a special constructor syntax that initializes the object to 0. Such as:

INT IVAL = INT ();

8. The pointer is used as a function parameter type, mainly used to pass an array or large class object.

9. Function pointer points to the code segment of the program.

10. Different types of pointers do not match each other's physical values, but is completely different from the interpretation of the memory layout and content of the memory.

11. To use strlen (), etc., the function of manipulating the C style string, you need to include the header file

#include

12. To use the String type, you need to include the header file

#include

13, average, String type implementation speed is twice the C style string.

14. Pointer (type such as const INT * P) of non-Const objects (such as const INT i), cannot modify the content referred to by the Const object; CONST pointer (type, like INT * Const Pi) The value cannot be changed, but it can modify the content you point to.

15. The reference must be initialized, and once defined cannot be changed. 16. When a reference is initialized with different types of objects or text constants, this reference must be defined as const (type, such as const IR). Cause: The internal storage of the reference is an address of an object. For both cases, the compiler must generate a temporary object to save them, and then use this temporary object to assign a reference. If it is assigned to this reference, the value of the temporary object is changed without changing the value of the object we want to change, which is transparent to us, and there is no practical meaning. So simply define this reference as const.

17. Const is the right binding to indicate semantics.

18, the object of the enumeration type can only be initialized or assigned by an object or enumeration member set in the same enumeration type.

19, the dimension must be a constant expression - that is, it must be possible to computer in compilation time. This means that non-Const variables cannot be used to specify the dimensions of the array.

20, const char ca1 [] = {'c', ' ', ' '}; and const char2 [] = "c "; difference, the latter dimension is 4, and the former is 3, because The latter's initialization value is a string with an empty character.

21, typedef is not macro expansion, such as:

Typedef char * cstring; extern const cstring cstr;

The second sentence is equivalent to

CHAR * Const CSTR;

Const modified CSTR.

22. The main purpose of the Volatile modifier is to prompt the compiler, the value of the object may change in the case where the compiler is not monitored. Therefore, the compiler cannot be arbitrarily optimized for the code to reference these objects.

23, as long as the function is called enough, the inline function can significantly improve performance.

24, SETW () is a predefined iostream manipulator, which is mostly the number of characters transmitted to it, such as:

CIN >> SETW (1024) >> Word;

转载请注明原文地址:https://www.9cbs.com/read-14755.html

New Post(0)