Key Difference Between C and C++
The main difference between c and c++ is that c is a procedural programming language while c++ supports both procedural programming as well as object-oriented programming. C does not support the oops concepts like object and classes while c++ is an object driven language in which we can write a program using classes and objects.
History C and C++
C Language was developed and invented by Dennis MacAlistair Ritchie (An American Computer Scientist) in while C++ founder was Bjarne Stroustrup (A Danish computer scientist). C Language was invented in the year of 1972 at AT & T Bell Labs, USA while C++ invention starts from 1979. initially, it was C with classes but later in 1983, it was renamed as c++.
What is C?
Introduction of C
- C is a general-purpose middle-level programming language.
- It is developed by Dennis M. Ritchie at AT & T Bell Labs, the USA in 1972.
- Initially, it was invented to develop UNIX Operating System.
- C is the successor of BCPL(Basic combined programming language) also called B language.
- In 1988 ANSI(American national standard institute) has formalized the C language.
- Linux OS, PHP, MySQL are written in c language.
Uses of C
C is used to developing System applications as follows
- Database System
- Language Interpreters
- Compiler and assemblers
- Operating System
- Network drivers
- Word processor(eg: WYSIWYG editor(Bravo)=>What you See Is What you get)
Data Types in C
Data Types and Sizes in C
|Type||Size(In Bits)||Size(In Bytes)||Range|
|char||8||1||-128 to 127|
|unsigned char||8||1||0 to 255|
|int||16||2||-215 to 215-1|
|unsigned int||16||2||0 to 216-1|
|short int||8||1||-128 to 127|
|unsigned short int||8||1||0 to 255|
|long int||32||4||-231 to 231-1|
|unsigned long int||32||4||0 to 232-1|
|float||32||4||3.4E-38 to 3.4E+38|
|double||64||8||1.7E-308 to 1.7E+308|
|long double||80||10||3.4E-4932 to 1.1E+4932|
Note: These sizes of data types might be differ from compiler to compiler.
What is C++?
Introduction of C++
- C++ is a general-purpose and case sensitive programming language.
- It is an object-oriented programming language.
- It is an extension to C programming.
- C++ developed by Bjarne Stroustrup.
- C++ Invention starts in 1979 at Bell Labs.
- It is considered a high-level language because it comprises(includes) a combination of both high-level and low-level language features.
- It is enhanced c language and initially, it was C with Classes but later in 1983, it was renamed as c++.
Object-Oriented Programming (OOPs)
C++ supports the object-oriented programming, the four major pillar of object-oriented programming used in C++ are:
C++ Standard Libraries
Standard C++ programming is divided into three important parts:
- The core library includes the data types, variables and literals, etc.
- The standard library includes the set of functions manipulating strings, files, etc.
- The Standard Template Library (STL) includes the set of methods manipulating a data structure.
Usage of c++
By the help of C++ programming language, we can develop different types of secured and robust applications:
- Windows application
- Client-Server application
- Device drivers
- Embedded firmware etc
Features of C
- It is a structured procedural programming language.
- It supports modularity.
- C is very fast and efficient.
- It is a general-purpose programming language.
- C is a middle-level language.
- Rich Library with multiple functions.
- C has a rich set of in-built operators.
- It is easy to extend.
- It supports pointers and memory management.
- It is a portable programming language.
- Varieties of data-types.
- It is statically typed.
- It is case sensitive programming language.
- It is a platform-dependent language.
- It is a compiler-based programming language.
Features of C++
- It is an object-oriented programming language.
- It is a cross-platform or platform independent programming language.
- It has a simple syntax.
- C++ support dynamic memory allocations.
- It is used to develop the Operating System.
- C++ is a very popular programming language.
- It is a high-level programming language.
- It has portability.
- C++ supports pointer and recursion.
- It is a universal language.
- C++ supports exception handling.
- Templates are also available in c++.
- C++ have data abstraction and data hiding feature.
- It is enhanced C language.
- It has operator-overloading and generic programming.
A Simple C and C++ Program Example
Note: We're doing programming on Turbo C++ IDE. If you want to download Turbo C++, click here
Comparison Between C and C++
C vs C++
|Definition||C is a general-purpose, mid-level, case-sensitive programming language which is developed by Denish M. Ritchie in 1972 at AT & T's Bell Labs USA.||C++ is an Object-Oriented, high-level, case-sensitive programming language which is developed by Bjarne Stroustrup in 1979 at Bell Labs.|
|Programming Language||C supports structured procedural programming.||While C++ supports Object-Oriented programming.|
|Origin||C language is based on assembly language.||C++ is based on C language.|
|Subset||C Programming is the subset of C++ programming.||While C++ can run 99% of C programs but C can't run C++ programs.|
|Security||In C language, data is less secure.||While C++ is a highly secure language.|
|Keywords||C has 32 keywords.||C++ supports 63 keywords.|
|Memory Allocation||C language supports malloc(), calloc(), realloc and for memory allocations and free() for memory de-allocation.||While in C++ memory allocation is done by the new operator and delete operator is used for memory de-allocation.|
|Header Files||C has stdio.h header file which library contains input and output functions.||C++ has iostream.h header files which have two classes Istream and Ostream. cin is the instance of Istream while cout is the instance of Ostream class.|
|Approach||C follows a top-down approach.||While C++ follows bottom-approach.|
|Virtual Function||C does not support virtual function.||C++ supports both virtual and pure virtual function.|
|Operator Overloading||Operator Overloading is not possible in C.||C++ supports the feature of Operator Overloading.|
|main() call||In C main() can be call from other functions.||While in C++ main() can't be called from other functions.|
|Namespaces||Not Available in C language.||Namespaces are available in C++.|
|I/O Functions||printf() and scanf() functions are used to take input and print the output on the console screen.||cin and cout objects are used to take the input and print the output on the console screen.|
|Exception Handliing||In C language there is no concept of exception handling.||While it is the main feature of C++.|
|Inline Function||C does not have an inline function.||While C++ supports the inline function.|
|Generic Programming||C does not support generic programming.||It supports generic programming.|
|Inheritance||Not supported in C language.||Supported in C++.|
|Templates||C language does support the feature of the template.||While C++ supports it.|
|Data Hiding||C does not support information hiding.||While C++ encapsulation is used for data hiding.|
|Reference Variables||Not supported in C.||C++ supports the reference variables.|
|Global Variables||Multiple declaration of global variables is allowed in C language.||While C++ does not allow.|
|Mapping||Mapping between data and function is difficult and complicated.||While in C++ mapping can be used using "Objects".|
|Extension||C language file extension is .c||While C++ file extension is .cpp|