Suggestion: use the post operator only when necessary.
The pre-operation requires less work. You only need to add 1 and then return the result after adding 1. The post operator must first save the original value of the operand to return the result of the operation without adding 1.
Comma OPERATOR: The expression is calculated from left to right. The result of a comma expression is the value of its rightmost expression.
The new expression returns a pointer to the newly created object. We can use this pointer to access the object.
Double * Pd = new double (33 );
Delete PD;
When creating a dynamic object, (almost) always initializing it is also a good way.
Int * Pi = new int; // There is no initialization.
Int * Pi = new int (); // The default initialization function is called, where it is initialized to 0.
Const int * PCI = new const int (1024 );
Delete PCI;
The const object created dynamically must be initialized at the time of creation and its value cannot be modified once initialized.
Const string * PCs = new const string; // call the default constructor for implicit initialization.
Class objects with built-in type objects or without Default constructors must be explicitly initialized.
Three CommonProgramError (related to dynamic memory)
1. Failed to delete the pointer pointing to the dynamically allocated memory (Memory leakage ).
2. Read and Write deleted objects. After deleting the pointer, set it to 0.
3. Use two Delete expressions for the same memory space.