This article is mainly for people with C language basis.
1. Basic syntax
- Object- object has state and behavior. For example: The state of a dog-color, name, variety, behavior-shake, bark, eat. An object is an instance of a class.
- A class- class can be defined as a template/blueprint that describes the behavior/state of an object.
- Method- Basically, a method represents a behavior. A class can contain multiple methods. You can write logic, manipulate data, and perform all actions in a method.
- Instant Variables- Each object has its own unique, immediate variable. The state of the object is created by the values of these immediate variables.
2. Data type
Base type: bool, char, int, float, double, void, wchar_t
Modifier: Signed, unsigned, short, long
A typedef can take a new name from a type already in place
int // feet defined as a new name for int
enum Enum type
Defines a collection of enumeration constants, with only a few possible values for a variable.
enum enum-name {identifier [= integer constant], identifier [= integer constant], ... Identifier [= integral type constant]} enumeration variable;
Key point:
1. If the enumeration is not initialized, the "= Integer Constant" is omitted, starting with the first identifier.
2. By default, the first name has a value of 0, the second name has a value of 1, the third name has a value of 2, and so on. However, you can also assign a special value to the name, just add an initial value.
3. Because by default, each name will be 1 larger than the one in front of it.
enum Color {red, green=5, blue};
In this example, the red value is the 0,green value of the 5,blue value of 6.
Example:
#include <iostream>using namespacestd;intMain () {enumDays{one, Three}day; Day=One ; Switch(day) { CaseOne:cout<<" One"<<Endl; Break; CaseTwo:cout<<" Both"<<Endl; Break; default: cout<<"three"<<Endl; Break; } return 0;}
This code is not clear.
3. Variable type
Case sensitive, must start with a letter or underscore.
Lvalues & Rvalues
Lvalues: An expression that points to a memory location that can appear to the left or right of an assignment number
Rvalues: Refers to a numeric value stored in memory for some address. The right value cannot be assigned to it, and can appear to the right of the assignment number, but not to the left.
4. Constants
Definition methods: #define and const
#define Identifier valueConst type variable = value;
5. Modifier type
| Qualifier |
meaning |
| Const |
Objects of the const type cannot be modified during program execution. |
| Volatile |
Modifier Volatile tells the compiler that the value of a variable may be changed in a manner not explicitly specified by the program. |
| Restrict |
A pointer decorated by restrict is the only way to access the object it points to. Only C99 adds a new type qualifier of restrict. |
C + + basic syntax