設為首頁收藏本站

艾歐踢論壇

 找回密碼
 立即註冊

QQ登錄

只需一步,快速開始

搜索
熱搜: 活動 交友 discuz
查看: 948|回復: 0
打印 上一主題 下一主題

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

[複製鏈接]
跳轉到指定樓層
樓主
發表於 2015-12-26 09:26:10 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
Difference between C and C++ – C Vs C++
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.
Comparison chart   Differences ✔
[td]

C
C++
Typing Discipline
Static, WeakStatic, Strong, Unsafe, Nominative
Paradigms
Imperative (procedural) systems implementation languageMulti-paradigm, Object-Oriented, Generic, Procedural, Functional, Meta
Designed by
Dennis RitchieBjarne Stroustrup
Influenced
awk, csh, C++, C#, Objective-C, BitC, D, Concurrent C, Java,JavaScript, Limbo, Perl, PHPAda 95, C#, Java, PHP, D, Aikido
Influenced by
B (BCPL,CPL), ALGOL 68, AssemblyC, Simula, Ada 83, ALGOL 68, CLU, ML
Major Implementations
GCC, MSVC, Borland C, Watcom CGNU Compiler Collection, Microsoft Visual C++, Borland C++ Builder, Intel C++ Compiler, LLVM/Clang
Appeared in
19721985
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 recompileAlmost anything, including OS-based and non OS-based platforms
Programming-String type
No 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.
Classes
Uses structures instead, and hence bestows more liberty to use internal design elementsclass and struct
Programming-input /output
scanf for input;printf for outputiostream, fstream (std::cin, std::cout)
Language Type
Procedural Oriented LanguageMulti-Paradigm Object Oriented Language
Developed by
Dennis Ritchie & Bell LabsBjarne Stroustrup
Execution Flow
Top to BottomTop to Bottom
Object-oriented
Not nativelyYes
Generic Programming
NoYes
Procedural Programming
YesYes
Functional Programming
YesPartial
Metaprogramming
NoYes
Reflection
NoNo
code
Compiled to native binary executable filesCompiled to native binary executable files
Inline comments delimiter
////
Block comments delimiter
/* and *//* and */
Statement terminators
;;
Multidimensional arrays supported
YesYes
Arrays dynamically sized
NoNo
Platform
Any that has a compilerAny that has a compiler

Comparison chart
—Similarities ✔
[td]

CC++
Programming-include
#include#include
Execution Flow
Top to BottomTop to Bottom
Procedural Programming
YesYes
Reflection
NoNo
code
Compiled to native binary executable filesCompiled to native binary executable files
Inline comments delimiter
////
Block comments delimiter
/* and *//* and */
Statement terminators
;;
Multidimensional arrays supported
YesYes
Arrays dynamically sized
NoNo
Platform
Any 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 的函式指標的技術。







分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 轉播轉播 分享分享 分享淘帖
回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

小黑屋|Archiver|手機版|艾歐踢創新工坊    

GMT+8, 2024-5-16 19:06 , Processed in 0.258052 second(s), 25 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表