C + + More emphasis on language practicality
1. All variables can be defined when they need to be used
I
int 0 ; for (int i=1; i<=3; i++) { for (int j=1; j<= 3; J + +) {+ = i * j; } }
2. Register keyword request compiler to store local variables in registers
-register keyword is still supported in C + +
-c++ compiler has its own optimization method
Cannot get the address of register variable in C language
Address of register variable can be obtained in C + +
Register keyword in C + +
When the C + + compiler discovers that the address of a register variable is required in a program, the register of the variable becomes invalid.
The early C language compiler does not optimize the code, so the register variable is a good complement
3, in the C language, it is legal to repeatedly define a global variable with the same name, and more than one global variable with the same name in C will eventually be linked to the same address space on the global data area.
In C + +, it is not allowed to define multiple global variables with the same name
4, the strengthening of the struct keyword
-C language struct defines a set of variables
-a struct-defined identifier is not a new type in the C language
Structs in-c++ are used to define a completely new type
5. What is the difference between void F () and void f (void)?
The type of claim that all identifiers in C + + must display
The default type in C is not legal in C + +
In the C language:
int F () represents a function that returns a value of int that accepts arbitrary arguments
F (void) indicates an parameterless function with a return value of int
In C + +
int f () and int f (void) have the same meaning
An parameterless function that represents a return value of int
C-to-C + + upgrade