C to C ++ relations

First, the relationship between the C and C ++

Relationship between C and C ++ schematic shown below:

As can be seen from the following figure:

  1. C ++ inherits all the characteristics of C
  2. C ++ syntax and provides more properties on the basis of C
  3. C ++ design goal is a unified operating efficiency and development efficiency
  4. C and C ++ is not a competition, but C ++ evolved from C.

Two, C to C ++ upgrade of

More emphasis on practicality C ++ language, all variables can be redefined when required for use, while the C language variables must begin in the position defined scope. The figure below shows how the C ++ code is defined variables.

    register keyword is a request to the compiler of the local variables are stored in registers, improving the efficiency of variable access, compatible with C ++ to C register keyword is still supported, but C ++ compilers optimized for a specific way. But C ++ compiler found that the program needs to take the division address register variable, register the statement of the amount will become invalid. The C language is unable to obtain the address of a variable register early C language compiler will not optimize the code, so register variable is a good supplement.

    In the C language, repeated to define multiple global variables with the same name is legitimate, more global variables with the same name will eventually be linked to the same address space, global data area. The C ++, does not allow the definition of global variables of the same name.

    Strengthen the struct keyword, C language struct defines a collection of variables and struct defined identifier is not a new type, keyword typedef required in order to define a new type. And a new type struct in C ++ is used to define. For example, shown below:

    C ++, all identifiers must be explicitly declared type, and the default type of C language is not legal in C ++; in C language, int f () represents the return value int, a function that accepts an arbitrary parameter; F ( void) returns the parameter-free function represents the value of int. In C ++, int F () and int f (void) have the same meaning, the return value represents a non-parametric function int. For example, FIG codes C and C ++ language will have a different interpretation.

在C语言中f(i)表示返回值为 int类型,可接受参数为int类型的函数。g()也是表示返回值为 int类型,可接受任意参数的函数。而在C++中,f()和g()都不是合法的函数。

三、总结

  1. C++更强调实用性,可以在任意的地方声明变量
  2. C++中的register只是一个兼容的作用,编译器能够更好的进行优化。
  3. C++中的任意标识符都必须显示指明类型。
发布了16 篇原创文章 · 获赞 1 · 访问量 2945

Guess you like

Origin blog.csdn.net/liqingjielihanjie/article/details/103285721
C