Relations and differences between C ++ and C

C ++ and C contact:

  C ++ is based on the C language to develop an object-oriented programming language, widely used. C ++ supports multiple programming paradigms - object-oriented programming, generic programming and procedural programming. Wide public areas of its programming, commonly used in system development, engine development and other applications, is one of the most majority of programmers benefit from the most powerful programming language support classes: classes, encapsulation, overloading and other features!

  C ++ add on the basis of the class C, C is a structured language, it focuses on algorithms and data structures. Design primary consideration of C programs is how to enter (or environmental conditions) arithmetic processing by a process to obtain an output (or the implementation process (transaction) control), and for C ++, the primary consideration is how to construct an object model, so this model can fit corresponding problem domain, which produces an output or implementation (transaction) is controlled by the state acquiring object information.

The difference between C ++ and C:

1, C is a process-oriented language, C ++ is an object-oriented language , then what is the object-oriented?

  Object-oriented: Object-oriented is an understanding of the real world and abstract methods, ideas, issues addressed by the demand elements into objects of thought.

2, C and C ++ dynamic memory management methods are not the same, C is the use of malloc, free function, and C ++ is not only malloc / free, as well as new / delete keyword. That malloc / free and new / delete difference?

  malloc / free and new / delete differences:

  ①, malloc / free standard C and C ++ library function language, new / delete the C ++ operator. They can be used to apply dynamic memory and free memory.

  ②, since malloc / free library function is not an operator, not within the scope of the compiler, the task can not be executed constructor and destructor strong added malloc / free. So C ++ can require a complete dynamic memory allocation and initialization of operator new, operator delete able to complete a clean-up work and free up memory.

  ③, new plus malloc performed may be considered a constructor. new pointer is out of the direct band type information. The pointer returned by malloc is void.

  ④, malloc is open space from the heap, while the new store is open from free (free store concept is abstracted from C ++, not only is the heap, can also be a static storage area).

  ⑤, malloc strictly designated for open space, and requires only new object name.

  ⑥, malloc memory If you open up too small, want to change a bigger, you can call relloc achieved, but there is no new intuitive way to change.

3, C ++ classes are not in C, C struct in C ++ can be used in a similar medium, struct and class differences that the members of the struct default access modifier is public, and the default class is private.

. 4, C ++ supports overloaded, overload and C does not support, wherein different support overloading C ++ C ++ and C modifiers names, for example in C ++ function int f (int) after name mangling becomes _f_int, and C is _f, so C ++ will support various different parameters call function.

5, C ++ has a reference, but C does not . It pointers and references What is the difference?

  The difference between pointers and references:  

  ①, the pointer has its own piece of space, and reference is just an alias.

  ②, sizeof view using a pointer size of 4 (32), the reference size is the size of the referenced object.

  ③, the pointer may be NULL, and reference must be initialized and must be a reference to an object to initialize.

  ④, passed as a parameter, needs to be dereferenced pointer can operate on an object, a reference to direct changes will change the reference object points.

  ⑤, in use, the pointer can point to other objects, but only a reference is a reference to the object, it can not be modified.

  ⑥, the pointer can have multiple level indicators (** p), while only one reference.

  ⑦, pointers and references to sense the ++ operator is not the same.

6, C ++ default attributes of all the variables connected to outer connections, and C is the connection.

7, modified by C const variable size when not in use define an array, but the C ++ variable can be modified by const.

8, C ++ has many unique input and output streams.

Published 33 original articles · won praise 30 · views 20000 +

Guess you like

Origin blog.csdn.net/baidu_15547923/article/details/100857184