S. No. | C | C++ |
1 | C is a structural or procedural programming language. | C++ is an object oriented programming language. |
2 | Emphasis is on procedure or steps to solve any problem. | Emphasis is on objects rather than procedure. |
3 | Functions are the fundamental building blocks. | Objects are the fundamental building blocks. |
4 | In C, the data is not secured. | Data is hidden and can’t be accessed by external functions. |
5 | C follows top down approach. | C++ follows bottom up approach |
6 | C uses scanf() and printf() function for standard input and output. | C++ uses cin>> and cout<< for standard input and output. |
7 | Variables must be defined at the beginning in the function. | Variables can be defined anywhere in the function. |
8 | In C, namespace feature is absent. | In C++, namespace feature is present. |
9 | C is a middle level language. | C++ is a high level language. |
10 | Programs are divided into modules and functions. | Programs are divided into classes and functions. |
11 | C doesn’t support exception handling directly. Can be done by using some other functions. | C++ supports exception handling. Done by using try and catch block. |
12 | Features like function overloading and operator overloading is not present. | C++ supports function overloading and operator overloading. |
13 | C program file is saved with .C extension. | C++ program file is saved with .CPP extension. |
C | C++ | |
Typing Discipline | Static, Weak | Static, Strong, Unsafe, Nominative |
Paradigms | Imperative (procedural) systems implementation language | Multi-paradigm, Object-Oriented, Generic, Procedural, Functional, Meta |
Designed by | Dennis Ritchie | Bjarne Stroustrup |
Influenced | awk, csh, C++, C#, Objective-C, BitC, D, Concurrent C, Java,JavaScript, Limbo, Perl, PHP | Ada 95, C#, Java, PHP, D, Aikido |
Influenced by | B (BCPL,CPL), ALGOL 68, Assembly | C, Simula, Ada 83, ALGOL 68, CLU, ML |
Major Implementations | GCC, MSVC, Borland C, Watcom C | GNU Compiler Collection, Microsoft Visual C++, Borland C++ Builder, Intel C++ Compiler, LLVM/Clang |
Appeared in | 1972 | 1985 |
Garbage Collection | Manual; allows better management of memory. | No GC available on the C++ standard library (STD). However, STD provides efficient and deterministic ways to manage resource such as object ownership and reference counting. |
Speed | C applications are faster to compile and execute than C++ applications | +-5% when compared with C if you know how to make a good use of C++. The performance of C++ and C programs can often be equal, since compilers for both languages are mature. |
Usual filename extensions | .c | .cc, .cpp, .cxx, .h, .hh, .hpp |
Programming-include | #include | #include |
Platforms | Almost anything on the planet; requires recompile | Almost anything, including OS-based and non OS-based platforms |
Programming-String type | No native string type; often declared as an array of characters | Array, std::string |
OOP (Object Oriented Programming) | Not built in; freedom to setup structures to act like objects. Lacks the ability to declare encapsulation. | Built in; size and memory layout of objects is deterministic. Virtual function calls can be done without vtable via CRTP. |
Classes | Uses structures instead, and hence bestows more liberty to use internal design elements | class and struct |
Programming-input /output | scanf for input;printf for output | iostream, fstream (std::cin, std::cout) |
Language Type | Procedural Oriented Language | Multi-Paradigm Object Oriented Language |
Developed by | Dennis Ritchie & Bell Labs | Bjarne Stroustrup |
Execution Flow | Top to Bottom | Top to Bottom |
Object-oriented | Not natively | Yes |
Generic Programming | No | Yes |
Procedural Programming | Yes | Yes |
Functional Programming | Yes | Partial |
Metaprogramming | No | Yes |
Reflection | No | No |
code | Compiled to native binary executable files | Compiled to native binary executable files |
Inline comments delimiter | // | // |
Block comments delimiter | /* and */ | /* and */ |
Statement terminators | ; | ; |
Multidimensional arrays supported | Yes | Yes |
Arrays dynamically sized | No | No |
Platform | Any that has a compiler | Any that has a compiler |
C | C++ | |
Programming-include | #include | #include |
Execution Flow | Top to Bottom | Top to Bottom |
Procedural Programming | Yes | Yes |
Reflection | No | No |
code | Compiled to native binary executable files | Compiled to native binary executable files |
Inline comments delimiter | // | // |
Block comments delimiter | /* and */ | /* and */ |
Statement terminators | ; | ; |
Multidimensional arrays supported | Yes | Yes |
Arrays dynamically sized | No | No |
Platform | Any that has a compiler | Any that has a compiler |
C | C++ |
1.Pass by Address | Reference |
2.Pass Array to Function | Vector |
3.char * | std::string |
4.Dynamic Allocation (malloc(),linked list) | STL container |
5.Function Pointer | Function Object |
6.N/A | Iterator |
7.N/A | Polymorphism |
8.N/A | Polymorphism object in container |
歡迎光臨 艾歐踢論壇 (http://www.iot.idv.tw/ucenter/) | Powered by Discuz! X3.2 |