C in relation to C + +:
C + + On the basis of the third language upgrade is the most important two aspects:
1, the type of strengthening, C + + is more high-level language, C + + language for the type of check more stringent
2, object-oriented support, natural support for object-oriented software development methodology
C + + language is the evolution of language.
C + + language more emphasis on the practicality of language, there are some grammatical aspects of strengthening
All variables can be defined when they need to be used
The variables in the C language must be defined at the beginning of the scope (old C language version)
Register Keyword:
Register keyword in the C language is very chicken, the compiler developed to the later stage, the optimization ability is very strong. Although C + + still supports register, this is only for compatibility with C language. C + + has its own optimization method, basically does not see whether there are regster keywords. Register in C + + in the form of a dummy.
Register keyword in C + +:
In the C language, it is legal to repeatedly define multiple global variables with the same name
In C + +, it is not allowed to define multiple global variables with the same name, and C + + directly rejects the practice of ambiguity
Multiple global variables with the same name in the C language will eventually be linked to the same address space on the global data area
Sample program:
The program variable C above is not defined at the starting scope of the main function, and I is also defined for the For loop, which is illegal in the C language and will be an error. Register variable A of type int, register is ignored by compiler in C + +.
C + + If you define two identical global variables, you will get a direct error:
Compiling with the GCC compiler will get the following error:
Strengthening of the struct keyword:
A struct in the C language defines a set of variables
struct-defined identifiers in C language are not a new type
Structs in C + + are used to define a completely new type
C + + has a type of reinforcement, very focused on type, C + + in the struct keyword as a definition of a new type of keyword, as long as the struct appears, C + + think of a completely new type. A typedef is required to define a new type in the C language.
In the equivalence definition above, the left side in the C language, the compiler thinks the struct defines a set of variables, and the set of this variable has a name called _tag_student, which is not a new type, and if it is to be used as a type, You must use the TypeDef keyword to define a type name. In the definition on the right, the C + + compiler considers a struct to define a new type of student.
Small questions during the interview:
identifiers: the default type in C is int, and if the function is not given a parameter or return value when it is defined, the default is int, that is, the return value of INT,F by default is int. The return value of G also defaults to int,g accepting arbitrary parameters by default.
This default type is definitely not allowed in modern software development because of the introduction of ambiguity. Therefore, C + + upgrades This default type so that int f () and int f (void) have the same meaning. and the int f (void) is written to be compatible with the C language.
2nd Class C to C + + upgrade