Chapter I.
1, preprocessor-#include <iostream> add iostream file contents to the program. The old C header file retains the extension. h, while the C + + header file does not have an extension.
(Some C header files are converted to C + + header files, remove extensions, and precede with C, such as Cmath)
2, namespaces-equivalent to Java in the package,using compiler directive is equivalent to the import in Java. When the header file does not have the. h prefix, classes, functions, and variables are standard components of the C + + compiler and are placed in the namespace Std.
3, the nature of the class-class is a user-defined data type. A class definition describes the data format and its usage, whereas an object is an entity created from the data format specification.
4, the return value (exit value) of main ()--main () is returned to the operating system. A typical exit value of 0 means that the program is running successfully.
Chapter II
5. The essence of oop--object-oriented programming is to design and extend its own data types to match types and data.
6, identifier--a name that begins with an underscore is reserved for the implementation as a global identifier; a name that increases the write letter with two underscores or underscores is reserved for use by the implementation (the compiler and the resource it uses).
(c + + has no limit on name length)
7. Integral type--short at least 16 bits; int is at least as short; long at least 32 bits long and at least the same length as int; Long long is at least 64 bits long and at least the length of a long.
8, byte--bytes usually refer to a 8-bit memory unit, while the bytes in C + + depend on the implementation.
9, operator--operator is a built-in language element. The sizeof operator returns the length (in bytes) of the type or variable. Therefore, the return value of sizeof (int) in different systems may be different.
10. Header file climits--defines a variety of symbolic constants that represent type limits. such as: #define INT_MAX 32767. (Designed as a C-usable header file, symbolic constants must be defined with #define compilation directives)
11, variable initialization--
A variable that is defined inside a function should be initialized at the time it is defined, otherwise its value is indeterminate, and the value saved for the corresponding memory unit before it is created.
(1), int a = 1; The traditional C initialization
(2), int B (2); New ways of C + +
(3), int c = {3} or int c{3}//C + + braces initializer for any type (in curly braces without anything, the variable is initialized to 0)
12, int--computer processing the most efficient length. Unless you use a suffix or a value that is too large, C + + typically stores an integer constant as an int type.
13, wcha_t--is the shaping type, there is enough space to represent the maximum extended character set used by the system. Use the wcin and wcout in iostream to process the wcha_t stream.
You can use the prefix L to indicate wide character constants and wide strings, such as wcha_t a = L ' P '; Wcout << L "Tall" << Endl;
(c++11 new Type char16_t and char32_t, all unsigned, 16-bit and 32-bit respectively, with prefix u for the former, prefix u for the latter)
14, Bool--c++ interprets 0 as false, and the non-0 is interpreted as true.
15, const--when creating constants, it is best to immediately assign values, such as cont int a = 5; constants typically capitalize the first letter.
16. Floating-point--float at least 32 digits, double at least 48 digits, and not less than float;long double at least as many as double. These three types of exponential range are at least 37-37.
(1), COUT.SETF () can control the output format, forcing cout to use fixed-point notation. Because cout usually deletes the 0 after the floating-point, as 3.3300000 is shown as 3.33.
(2), floating-point constants are usually double, usually with the suffix F or f, specifying a float type, with the suffix L or l specifying a long double type.
17, Force type conversion--
such as: (long) thorn or Long (thorn)
Forcing type conversions does not modify the thorn itself, but instead creates a new, specified type of value.
You can also do this: static_cast<long> (Thorn), which is more restrictive than the traditional coercion type conversion.
18, auto--automatic inference type, keyword auto can not specify the type of variable, the compiler automatically set the type of the variable to be the same as the original value, such as auto a = 100;
However, auto is typically used to handle complex types
Fourth Chapter
19, array--
(1), declare the general format of the array: TypeName Arrayname[arraysize], such as int a[5];
(The compiler does not check that the subscript used is valid.) )
(2) If there is no array defined in the initialization function, the value of the element is the value that previously resided in that memory. (As with variables in a function)
(3), the sizeof function and the array name, the total number of bytes in the entire array is obtained. When acting on an element, you get the number of bytes for that element.
(4), only when the array is defined to initialize, and then not. Can be partially initialized, such as: int a[5] = {1,2}, when partially initialized, the compiler sets the other elements to 0.
You can do this: int b[] = {1,2,3,4,5}; Let the compiler compute the number of elements.
(5), you can omit the equal sign (=) When you use the list to initialize the array, and all the elements in the curly braces that contain no content are 0; The list initialization suppresses narrowing conversions.
20, string--
A string is a series of characters stored in contiguous bytes of memory.
(1) The C-style string ends with a null character with an ASCII code of 0, such as: char dog[7] = {' A ', ' B ', ' C ', ' d ', ' e ', ' f ', ' n '}; Note that the array length must be computed '
(2), string constants, such as: char cat[] = "Cat";
Attention ' s ' represents the constants of the word, whereas "s" denotes a string consisting of ' s ' and ' two characters ', and "s" actually represents the memory address where the string is located.
(3), when the string is spliced, the last ' "' of the first string is replaced by the first character of the second string.
(4) The strlen () function returns the length of the string stored in the array, containing only the visible characters, excluding the null characters.
(5), CIN uses whitespace (spaces, tabs, and line breaks) to determine the end position of the string, so when it reads the array input, it reads only the first word and automatically adds the null character.
(6), line-oriented input has getline () and get (), all of which are used to determine the end of the input by a newline character, and the difference is that the fetch () does not read and discard line breaks.
Cin.getline (name,arsize), reads ArSize-1 characters into the name array. For Get (), you can use this: Cin.get (name,arsize).
(7), read the empty line, get () will set the expiration bit, if the input row contains more than specified number of characters, Getline () will set the expiration bit. The subsequent input will be blocked.
(8), allow: char c[] = {"Hello world!"};
(9), the string class has the function of automatic resizing, so it is more secure.
(10), strcpy (STR1,STR2) copies str2 to STR1, strcat (STR1,STR2) attaches str2 to the end of str1.
(11), Str1.size () and strlen (STR1) function the same. The former is a method of the string class, which is a regular function.
21, Raw (RAW) string--the original string, \ n does not represent a newline character, such as: Default delimiter (and) cout << R "(Don t use" \ n ", OK?)" << '; " Output: Don ' t use "\ n", OK?
Custom delimiter +* (and) +* cout << R "+* (" (Don t use "\ n", OK?)) +* "<< ' \ n"; Output: "(don ' t use" \ n ", OK)"
22, Structure--
(1), definition: struct man {char name[20]; Double weight; int age; };
(2), declaration, allows omitting the keyword struct, such as: Man Mike;
(3), initialization: Man Mike {"Mike", 56.2, 22};
(4), using the member operator (.) To access individual members.
(5) Defining the structure and creating variables at the same time: struct man {char name[20]; Double weight; int age; Mike = {"Mike", 56.2, Jim;
(6), also can declare anonymous structure: struct {int x, int y} point;
23, the bit field in the structure-specifies the structure member that occupies a specific number of digits, such as: struct my_bit {unsigned int x:4; BOOL Y:1; };
24. External Declaration--the declaration outside the function. C + + does not advocate the use of external variables, advocating the use of external declarations.
25, the common use of the body--
A data format that stores different data types, but only one of them can be stored at the same time, and is often used to conserve memory. Such as: Union ID {long long_id; Char char_id; };
(1), because the common body can store only one value at a time, its length is the length of the largest member.
(2) The anonymous common body does not have a name, and its members become variables at the same address, and only one member is the current member at a time.
26, enumeration--
Another way to create symbolic constants is to replace the Const. such as: Enum Spectrum {A, B, C, D, f};
(1), by default, a, B, C, D, f as symbolic constants, corresponding to 0 to 4.
(2), for enumerations, only the assignment operator is defined, and no arithmetic operations are defined.
(3), you can assign an enumeration variable only to the enumerator used when defining the enumeration.
(4), you can use the assignment operator to explicitly set the value of an enumerator. such as: enum bits {A, zero = 0, two =, three, four}; Here the value of three is 201, and the value of 0
(5), the value range of the enumeration. The maximum value for BITS is 202, which is greater than the power of the smallest 2 is 256, so bits has a range of 0-255
(6), by forcing type conversions, increases the legal value that can be assigned to an enumeration variable, as long as it is within the range of values. such as: bits B = bits (240);
27, the pointer--
A pointer is a variable that stores the address of the value, not the value itself.
(1) The address operator (&) can obtain the location of the variable (the storage address).
(2), pointer, view the address as the specified amount, and treat the value as a derived quantity. The pointer name represents an address.
(3), the * operator is referred to as an indirect value (dereference) operator. For pointers, you can get the value of the pointer address store.
(4), Declaration: int * A; The spaces on either side of the * operator are optional int * b, C; Create pointer b and int variable c, each pointer requires a *
(5), initialization: int * a = &b; Set the value of pointer A to &B
(6), be sure to initialize the pointer to a determined, appropriate address before using the dereference operator (*) on the pointer.
(7) Assigning a number to the address: int * pt = (int *) 0x8000000;
(8), allocating memory: int *pn = new int; Allocates memory from a heap (heap) or memory area that has only a storage area (free store).
28, Array--
(1), compile time to allocate the memory of the array is called the Static Union, the program runs the choice array length is called the Dynamic Union.
(2), creating a dynamic array: int * p = new int [10]; P is the address of the first element of the element
(3), releasing the array: delete [] p; You can only release the memory allocated by new, cannot delete two times, the null pointer delete security, and the array is released with delete [].
(4), you cannot use the sizeof operator to determine the number of bytes that the dynamically allocated array contains.
(5), using an array: P[0] is the first element, and P[1] is the second. C + + Internal use pointers to handle arrays, p[1] is considered * (p+1)
(6), p = p + 1; After the pointer variable plus 1, the increment is the number of bytes of the type it points to.
(7), in most cases, C + + interprets the array name as the address of the first element in a group.
(8), pointer and array name difference: You can modify the value of the pointer, and the array name is a constant, the array names using sizeof to get the number of bytes of the arrays, and the pointer using sizeof to get the length of the pointer.
(9), short tell[10]; cout << tell; The array name itself is the address of its first element, such as: &tell[0], which is the address of a 2-byte memory block.
cout << &tell; The output is the address of a 20-byte memory block.
(10), give cout the address of a character, which will print from that character until it encounters a null character.
(11) To print the address of a pointer, the pointer must be strongly converted to another type of pointer, such as (int *) p;
29, use new to create dynamic structure--struct1 * s = new Struct1; At this point, the struct identifier is a pointer, so you cannot use the member operator period (.).
Members can be accessed only by using the Arrow member operator (->) or by using (*s). Price.
30, automatic storage, static storage and dynamic storage--
(1), the function of the definition of the general variable for automatic variables, stored in the stack, LIFO (LIFO), program execution, and constantly increase the narrowing. For automatic storage.
(2), defined outside the function, or declaring a variable to use the static keyword as a static variable. Static storage is a variable that exists throughout the execution period of the program.
(3), the variable created using new is dynamic storage. The new and delete admin class is a memory pool called free store or heap.
Attention The automatic add and remove mechanisms in the stack make the memory used continuously, while new and delete may cause only the store to be discontinuous.
31, template class vector--similar to String, is also a dynamic array, using new to create a substitute for dynamic array, automatically using new and delete to manage memory.
#include <vector> using namespace std; Contains header files, vector in Std namespace
Vector<int> Ele (10); Create a Vector object named Ele that can store 10 elements of type int.
(Note that the list of available c++11 is initialized.) Type can be a variable)
32, template class array--and arrays, the length of fixed, using stack storage, efficiency and array of the same, and more convenient and safe.
#include <array> using namespace std; Array<int,5> arr; An array object named ARR that contains 5 int elements.
(Note that the type cannot be a variable!) Available list initialization)