This chapter mainly introduces the basic data types in c ++ and some programming skills.
The record has the following points:
1. By adding a suffix, You can forcibly convert the literal value integer constant to the long or unsigned, unsigned long type, such
1L/* long */
Adding L after decimal point indicates the extended precision.
2. Differences between declarations and definitions:
The definition is used to allocate a bucket for a variable. You can also specify an initial value for the variable. The declaration is used to indicate the type and name of the variable to the program.
Variables must be defined only once, and must be defined or declared before using variables.
3. It is recommended that you do not directly use numbers in cyclic condition statements, such
For (int index = 0; index! = 512; ++ index)
{...}
It is best to write:
Int bufSize = 512;
For (int index = 0; index! = BufSize; ++ index)
{...}
It mainly improves readability and robustness;
4. Use of const
1) define a const object
The object defined by const is a constant, which must be initialized and cannot be modified later.
In the global range, non-const variables are extren by default. To make the const variable accessible in other files, you must explicitly specify it as extren.
5. Reference
A reference is the alias of a variable, as shown in figure
# Include <iostream>
Using namespace std;
Int main ()
{
Int a = 1;
Int & refer =;
Refer + = 2;
Cout <a <endl;
Return 0;
}
3 is output here.
For const reference,
A const reference is a reference to a const object. It can be bound to a different but related type object or to the right value,
A non-const reference points to a non-const type reference and can only be bound to an object of the same type as the reference.
6. Functions of typedef
1) To hide the implementation of specific types, emphasize the new purpose of using classes;
2) simplify complicated type definitions to make them easier to understand;
3) allow one type to be used for multiple purposes, and clarify the purpose of using this type each time.
The personal feeling is to enhance the readability of the program.
7. Objects of the enumeration type can only be initialized or assigned values through enumeration members or other objects of the same Enumeration type;
An enumerated member is a constant expression, so it can be used anywhere where a constant expression is needed.
8. The header file should not contain the definition of variables or functions. If you are concerned about exceptions, you can define classes and const objects and inline functions that are known at compilation;
9 when designing a header file, you must make sure that the file is included multiple times in the same source file. The general practice is to use a Preprocessor to define header file delimiters.
Example:
# Ifndef SALESITEM_H
# Define SALESITEM_H
// Define a class
# Endif
Note:
# Ifndef checks whether the specified Preprocessor variable is undefined.
# Define accepts a name and defines it as a preprocessing variable. Then execute the following definition, # endif indicates the end.
From left-brain design, right-brain Programming