admin 發表於 2015-12-26 09:26:10

Difference between C and C++ < C Vs C++>

Difference between C and C++ – C Vs C++
S. No.CC++
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.

Comparison chart   Differences ✔


C
C++

Typing DisciplineStatic, WeakStatic, Strong, Unsafe, Nominative
ParadigmsImperative (procedural) systems implementation languageMulti-paradigm, Object-Oriented, Generic, Procedural, Functional, Meta
Designed byDennis RitchieBjarne Stroustrup
Influencedawk, csh, C++, C#, Objective-C, BitC, D, Concurrent C, Java,JavaScript, Limbo, Perl, PHPAda 95, C#, Java, PHP, D, Aikido
Influenced byB (BCPL,CPL), ALGOL 68, AssemblyC, Simula, Ada 83, ALGOL 68, CLU, ML
Major ImplementationsGCC, MSVC, Borland C, Watcom CGNU Compiler Collection, Microsoft Visual C++, Borland C++ Builder, Intel C++ Compiler, LLVM/Clang
Appeared in19721985
Garbage CollectionManual; 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.
SpeedC 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
PlatformsAlmost anything on the planet; requires recompileAlmost anything, including OS-based and non OS-based platforms
Programming-String typeNo native string type; often declared as an array of charactersArray, 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.
ClassesUses structures instead, and hence bestows more liberty to use internal design elementsclass and struct
Programming-input /outputscanf for input;printf for outputiostream, fstream (std::cin, std::cout)
Language TypeProcedural Oriented LanguageMulti-Paradigm Object Oriented Language
Developed byDennis Ritchie & Bell LabsBjarne Stroustrup
Execution FlowTop to BottomTop to Bottom
Object-orientedNot nativelyYes
Generic ProgrammingNoYes
Procedural ProgrammingYesYes
Functional ProgrammingYesPartial
MetaprogrammingNoYes
ReflectionNoNo
codeCompiled to native binary executable filesCompiled to native binary executable files
Inline comments delimiter////
Block comments delimiter/* and *//* and */
Statement terminators;;
Multidimensional arrays supportedYesYes
Arrays dynamically sizedNoNo
PlatformAny that has a compilerAny that has a compiler

Comparison chart—Similarities ✔


CC++
Programming-include#include#include
Execution FlowTop to BottomTop to Bottom
Procedural ProgrammingYesYes
ReflectionNoNo
codeCompiled to native binary executable filesCompiled to native binary executable files
Inline comments delimiter////
Block comments delimiter/* and *//* and */
Statement terminators;;
Multidimensional arrays supportedYesYes
Arrays dynamically sizedNoNo
PlatformAny that has a compilerAny that has a compiler

C很多地方都用到pointer,C++則有不少替代方案,以下是C和C++會用到pointer的地方。


CC++
1.Pass by AddressReference
2.Pass Array to FunctionVector
3.char *std::string
4.Dynamic Allocation
(malloc(),linked list)STL container
5.Function PointerFunction Object
6.N/AIterator
7.N/APolymorphism
8.N/APolymorphism object in container




C++ 為了達成兼容效率和彈性的理念,在不 斷發展進化的過程中,直至目前為止,已綜合歸納出,並且實現了四種不同,而又相輔相成的程式設計的思維模式:
[*]procedural-based paradigm
[*]object-based paradigm  
[*]object-oriented paradigm
[*]generic paradigm                                     

C 和 C++ 的不同之處就在於,以上所列 C++ 的四 種編程思維,C 只提拱了第一種,也就是我們常聽到的「程序功(能)導向」模式--把功能切割成適當的小模組,在 C 語言中就是一個一個小函式,再按需求靈巧的編排組織起來。
必須特別提到一點,C 之所以受許多程式設計師青睞(也同時令另一些人望之卻步)的其中一個原因就在於:
C 擁有指標的設計,可以在最大限度的範圍內,自由靈活地操控記憶體。而在嚴謹的程序導向編程思維的年代,像 C 這種支援指向函式的指標這類禁斷技術的語言,會在眾語言百家爭鳴下脫穎而出,也就不太意外了。      
C++ 承續了 C,當然也支援函式指標,但 C++ 程式的風格,並不鼓勵使用指向函式的指標。在 C++ 中,提供了一種更嚴謹、具備型別安全(type safe)、更一致明確的語法表達、更加具有彈性和擴充性,且更有效率的函式物件(function object),來取代 C 的函式指標的技術。







頁: [1]
查看完整版本: Difference between C and C++ < C Vs C++>