C, C ++ array initialization:
Array: A group of Structural Types ordered by the same type of elements.
Two features: 1. the array element type is the same. 2. Each element is placed in the continuous memory area.
C and C ++ do not provide array out-of-bounds detection. Valid array access spaces are 0-n-1.
Array initialization:
Int a [5] = {0}; Initialize all elements to 0, while
Int B [5] = {1}; initialize the first element to 1, and initialize the other n-1 elements to 0;
Int c [] = {1, 2, 3, 4, 5}; automatically sets the array length to 5.
The differences between the C ++ template class and the class template:
[Cpp]
Template <class T>
Class {
Public:
A {};
~ A {};
Void show ()
{
Cout <n <endl;
};
Void setN (T mn)
{
N = mn;
};
Private:
T n;
}
Template <class T>
Class {
Public:
A {};
~ A {};
Void show ()
{
Cout <n <endl;
};
Void setN (T mn)
{
N = mn;
};
Private:
T n;
}
The above defines a class template. Compile the following statement:
A <int>;
The compiler generates a template class using the class template:
[Cpp]
Class {
Public:
A {};
~ A {};
Void show ()
{
Cout <n <endl;
};
Void setN (int mn)
{
N = mn;
};
Private:
Int n;
}
Class {
Public:
A {};
~ A {};
Void show ()
{
Cout <n <endl;
};
Void setN (int mn)
{
N = mn;
};
Private:
Int n;
}
Then, this template class is used to instantiate object.
The same is true for template functions and function templates. The Compiler does not actually generate any code for function templates or class templates.
Another thing to be clear is that a class template is a template, that is, a class, and a template class is a class. Class templates can be used as function parameters.
Relationship between Template classes, class templates, function templates, and template functions:
A class template is in the class hierarchy
It can be either a base class or a derived class:
A class template can be derived from a template class.
Class templates can be derived from non-template classes
Template classes can be derived from class templates
Non-template classes can be derived from class templates
Operator overload:
The overload operator of the member function is often used when the type of the left and right operands of the operator is different.
Operator functions can be reloaded as member functions or member functions. The key difference is that the member function has the this pointer, but the member function does not. The member function can transmit less than one parameter object.
Whether it is a member function or a member function overload, operators are used in the same way. However, the method for passing parameters is different, and the implementation code is different, and the application scenario is also different.
It is best to use friend functions:
1. The first parameter is an internal type variable.
2. If the operator's operand (especially the first operand) needs implicit conversion, it must be overloaded by the user function.
In C ++, you cannot use the following operators to overload functions:
= () []->
Single Object operator overload:
<Function type> operator ++ (); // prefix operator ++ <Object> member functions are interpreted as <Object>. operator ++ (), which is interpreted as a friend <Object>. operator ++ (A &)
<Function type> operator ++ (int); // suffix operator <Object> ++ member functions are interpreted as <Object>. operator ++ (0). The friend function is interpreted as a friend <Object>. operator ++ (A & a, 0 );
The suffix operator overload adds a pseudo parameter to distinguish it from the prefix operation.
C format input and output:
Printf function:
Additional Function Description
Description
L
Used for output of long integer data. It can be added with the format characters u, x, o, and d. For example, ld % indicates the output of long integer numbers in a 10-digit format.
M (a positive integer)
The minimum width of the output minimum data. If the actual width of the data exceeds m, the output is based on the actual width. If the actual width is smaller than m, the left side is filled with 0 or spaces, and the right is aligned.
. N (a positive integer)
For real numbers, n decimal places are output; for strings, n characters are truncated.
-M (a negative integer) or a separate-Number
Left alignment of output characters or numbers
Scanf Functions
Additional format description
Description
L
Used to input long integer data (can be used for % ld, % lo, % lx); used to input double type data (% ld or % le can be used)
H
Used to input short integer data (can be used for % hd, % ho, % hx)
Field width (a positive integer)
Used to specify the width (number of columns) of input data)
*
Used to indicate that the input item is not assigned to the corresponding variable after the input.