First, start
(i) Input and output
The role of 1.endl
The Endl operator is used to end the current line and flush the buffer contents associated with the device to the device. Without this character, once the program crashes suddenly, it can cause the output to remain in the buffer without displaying to the device.
2. Understanding of input and output operator return values
">>" and "<<" are operators whose function is to put the operand to the left of it.
3. The input and output operators can automatically determine the data format of the Operation object, and do not need to format the input and output parameters like the C-language printf and scanf functions. Because different versions of the input and output operators (overloads) are defined in the standard library. )
3. Enter the state of the operator, for example, Std::cin >> value, which returns non-true if the user enters an illegal time (data type mismatch or the end of input is encountered).
Ii. variables and basic types
(i) basic built-in type
1. The basic data types include arithmetic types and empty types, where the arithmetic type consists of characters, shapes, Booleans, and 4 types of floating-point numbers. Characters, shaping numbers, and Boolean values can be categorized into one category, and floating-point numbers belong to another category.
C + + arithmetic types
Big class |
Specific type |
Meaning |
Minimum size |
Actual Size (Windows 64bit System) |
Plastic |
bool |
Boolean type, which is actually 0 and 1 |
Not defined |
8 |
Char |
Character type |
8 Guests |
8 |
wchar_t |
Wide character (wide character type before Unicode appears) |
16 Guests |
16 |
char16_t |
Unicode characters |
16 |
16 |
char32_t |
Unicode characters |
32 |
32 |
Short |
Short-integer |
16 |
16 |
Int |
Plastic |
16 |
32 |
Long |
Long integer type |
32 |
32 |
Long Long |
Long Integer (two overlay usage is also a data type) |
64 |
64 |
Floating point Type |
Float |
Single-precision floating-point number |
6-digit valid digits |
32 |
Double |
Double-precision floating-point number |
10-digit valid digits |
64 |
Long double |
Extended precision floating point number |
10-digit valid digits |
12 |
Length regulation: Int>=short,long>=int,long Long>=long
There are three types of character types: char,signed char and unsigned char, and three are not the same type. However, the exact meaning of char and signed Char is distinguished by the compiler's decision.
A string constant is actually an array of character constants, and the compiler adds 1 empty characters after the array.
cout output character variables, such as Char = ' a ', are not output "a", but correspond to ASCII numbers.
(ii) variables
1. The concept of variables. Variable provides a named storage space that can be manipulated by the program. In C + +, variables and objects have the same meaning.
2. Initialize the problem. In C + +, when declaring a variable using the "=" symbol, it is initialized, not an assignment statement.
3. Initialization form. In the new C + + standard, the full application of {} to initialize objects (including variables and class objects), such as int a{9}.
4. Declaration and definition of variables. If you are simply declaring a variable, use the extern keyword, such as extern int A. A variable can be declared more than once, but only once.
5. The reference must be initialized and cannot be changed after initialization.
6. Some concepts of obscure constants (const).
(1) Pointers and references to constants must also correspond to constant pointers and references. A const reference is not allowed to bind a constant, but allows a constant reference to bind a very amount; in the same vein, a non-const pointer is not allowed to point to a constant, but allows a constant pointer to point to a very mass. For example:
const int a = 1;
const int &b = A; That's right.
int a2 = 3;
int &b2 = a;//error, reference mismatch.
However, a constant reference is allowed to be bound to a very good amount, for example:
Cons tint &reb = A2;
Const double PI = 3.14;
Double *ppi = π Error, the very magnitude pointer points to a constant.
But in turn allows, for example:
Double pi2 = 3.14;
Const double *PPI2 = &pi2; correctly, a constant pointer is allowed to point to a very amount.
(2) The concept of a top-level const pointer and the underlying const pointer. In fact, it mainly involves two concepts, one is that the variable is a const variable, that is, the variable cannot be changed, and the pointer itself is a constant, and the pointer cannot be changed, called a constant pointer. This is explained by the following example:
Const double PI = 3.14;
Double rate = 0.68;
Double * Const PRATE = &rate; OK, this is a constant pointer to the very amount
Const DOUBLE * PPi = π//ok, normal pointer to constant
Const DOUBLE * Const CPPI = π//ok, constant pointer to constant.
(3) The requirement of constant expression. The lvalue is defined as a constant, and the right value should be a constant, meaning that his value can be determined at compile time.
(c) Type alias (typedef)
typedef char *pstring;
Const Pstring CStr = 0, this statement's understanding cannot use the simple substitution method, otherwise may draw the wrong meaning. The correct way to understand this is to equate pstring with a data type, so the const of this sentence is a modifier of the pointer, expressed as a constant of type pstring, equivalent to a constant pointer to char, not a pointer to a char constant as indicated by the const char *. Although they are pointers, they are of different meanings.
Three, array
(a) initialization and assignment of arrays should be noted
1. There is no direct assignment between arrays, that is, the array name cannot be assigned directly.
2. Several examples of complex array declarations:
int * PTRS[10]//ptrs is an array that contains 10 shaping pointers.
int &REFS[10]//error, there is no array of references.
int (*parray) [//parray] is a pointer to a 10-D integer group.
int (&ARRAYREF) [ten]//arrayref is a reference to an array of 10-D shaping.
int * (&ARRAYREF) [ten]//arrayref is a reference to an array of 10-d shaping pointers.
The best way to understand the meaning of an array declaration is to start with the name of the array and read from the inside out.
(ii) The relationship between arrays and pointers
1. The array name and the corresponding type of pointers are mutually equivalent (but the array name cannot be + + or-operation). When the array name is used, it is automatically replaced by the compiler with a pointer to the first element of the array.
For example int a[10] = {0}; Then there is an int *parr = A, equivalent to int *parr = &a[0];
C + + Primmer Learning notes