C和C++之间的相似之处是:
- 两种语言都有相似的语法。
- 两种语言的代码结构相同。
- 两种语言的编译是相似的。
- 它们共享相同的基本语法。几乎所有C的运算符和关键字也都存在于C++中,并且执行相同的操作。
- C++的语法比C略有扩展,但是基本语法是相同的。
- 两者的基本内存模型都非常接近硬件。
- 两种语言都具有相同的堆栈,堆,文件作用域和静态变量的概念。
C和C++之间的区别是:
C++可以说是C的超集。C++的主要新增功能是面向对象的程序设计,异常处理和丰富的C++库。
下表是C和C++之间的区别表:
C | C++ |
---|---|
C was developed by Dennis Ritchie between the year 1969 and 1973 at AT&T Bell Labs. | C++ was developed by Bjarne Stroustrup in 1979. |
C does no support polymorphism, encapsulation, and inheritance which means that C does not support object oriented programming. | C++ supports polymorphism, encapsulation, and inheritance because it is an object oriented programming language. |
C is a subset of C++. | C++ is a superset of C. |
C contains 32 keywords. | C++ contains 63 keywords. |
For the development of code, C supports procedural programming. | C++ is known as hybrid language because C++ supports both procedural and object oriented programming paradigms. |
Data and functions are separated in C because it is a procedural programming language. | Data and functions are encapsulated together in form of an object in C++. |
C does not support information hiding. | Data is hidden by the Encapsulation to ensure that data structures and operators are used as intended. |
Built-in data types is supported in C. | Built-in & user-defined data types is supported in C++. |
C is a function driven language because C is a procedural programming language. | C++ is an object driven language because it is an object oriented programming. |
Function and operator overloading is not supported in C. | Function and operator overloading is supported by C++. |
C is a function-driven language. | C++ is an object-driven language |
Functions in C are not defined inside structures. | Functions can be used inside a structure in C++. |
Namespace features are not present inside the C. | Namespace is used by C++, which avoid name collisions. |
Header file used by C is stdio.h. | Header file used by C++ is iostream.h. |
Reference variables are not supported by C. | Reference variables are supported by C++. |
Virtual and friend functions are not supported by C. | Virtual and friend functions are supported by C++. |
C does not support inheritance. | C++ supports inheritance. |
Instead of focusing on data, C focuses on method or process. | C++ focuses on data instead of focusing on method or procedure. |
C provides malloc() and calloc() functions for dynamic memory allocation, and free() for memory de-allocation. | C++ provides new operator for memory allocation and delete operator for memory de-allocation. |
Direct support for exception handling is not supported by C. | Exception handling is supported by C++. |
scanf() and printf() functions are used for input/output in C. | cin and cout are used for input/output in C++. |
C structures don’t have access modifiers. | C++ structures have access modifiers. |
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程” 。