Ad Code

C v/s C++

26 differences between C programming language and C++ programming language



Before we talk about the differences between C and C++ programming language, let's talk about the similarities in both the languages.

     Similarities in both the languages

  • The syntax of both the languages are same.
  • The structure of codes in both the languages are same.
  • The compilation is also similar.
  • C++almost contains all the operators and keywords that are used in C programming language. Hence they share the same basic syntax.
  • The basic memory model of both the languages is very close to the hardware.
  • Notions of stacks, heap, file scope and static variables are present in both the programming languages.
  • Both of the languages support pointers

Differences in both the languages


Comparison on the basis of the following

C     Programming Language

C++ Programming Language

Development year and place

C was developed by Dennis Ritchie at AT&T Bell Labs between the year 1969 and 1973.

C++ was developed by Bjarne Stroustrup in 1979.

Programming approach

C does no support polymorphism, encapsulation, and inheritance because C does not support object oriented programming. C is a procedural language, it follows a top-down approach of programming.

C++ supports polymorphism, encapsulation, and inheritance because it is an object oriented programming language. C++ follows a bottom-up approach to programming.

Data Types

C programming language supports only primitive and fixed data types, i.e., the basic version of programming language.

C++ is an extended version of C and supports generic data types. C++ also supports Boolean and string data types.

Exception Handling

 

C program does not support exception handling.

  

C++ supports exception handling and provides efficient support during errors and incorrect codes.

Application Development

C is more suitable for assemblers, text editors, network drivers, and low-level implementations.

C++ is suitable and extensible for high-end programming including game development, embedded systems like smart watches, medical machines, etc.

Compatibility

C does not support object-oriented features of C++ and hence it is not compatible with C++ programs. Therefore programs written in C++ will not run on C compilers.


C language is generally not compatible with other generic programming languages.

C++ is a subset of C and takes most of its procedural constructs from the C programming language. Thus any C program will compile and run fine with the C++ compiler.


C++ language is generally compatible with other generic programming languages.

Division of program

C is divided into functions and modules and they are called by the main function or other functions for execution.

C++ is divided into classes and objects. The program is divided into classes and the objects and classes are the executing units that are created by the main functions and are executed.

Global variables

C allows multiple declaration of global variables

C++ does not allows multiple declaration of global variables

Keywords

C program contains 32 keywords

C++ program contains 63 keywords

Inline Function

C does not support inline function.

C++ supports inline functions.

Data and functions

Data and functions are separated in C because it is a procedural programming language.

 

In C++, Data and functions are encapsulated together in form of an object.

Inheritance

C does not support inheritance

Inheritance is also an important feature of object-oriented programming that is supported by C++

Information hiding

C does not support information hiding.

Data is hidden by the Encapsulation to ensure that data structures and operators are used as intended.

Functions

C does not support functions with default arrangements like default parameters etc.

C++ supports functions with default arrangements.

Namespaces

Namespaces are not supported in C

Namespaces are supported by C++.

Abstraction

C does not supports this feature

C++ supports this feature

Polymorphism

C has no support for object-oriented programming and does not support polymorphism.

Being an object-oriented language, C++ supports polymorphism.

Memory management

C uses functions like malloc (), calloc (), realloc (), etc., to allocate memory and free () function to free the memory.

C++ uses new () and delete () operators to allocate and de-allocate the memory respectively.

Classes & Objects

C programming language is a procedural language and hence it does not support the concept of classes and objects.

C++ programming language supports the concept of classes and objects and almost all the applications in C++ are built around classes and objects.

Function Overloading

C does not support this feature.

Function Overloading is an important feature of object-oriented programming.

main() Function

C can have a main() function called by the other functions in the code.

C++ cannot call a main() function from any other point. The main() function is the single execution point.

Data Security

In C, the main emphasis is on functions or procedures rather than on data. Hence as far as data security is concerned, it is negligible in C.

In C++, as we are dealing with classes and objects, the main building block of the program is Data. Thus, data is tightly secured using classes, access specifiers, encapsulation, etc.

File Extension

C are usually saved with “.c” extension

C++ programs are saved with the “.cpp” extension.

Header files

Header file used by C is stdio.h.

Header file used by C++ is iostream.h.

Standard Input Output functions

scanf() and printf() functions are used for input/output in C.


cin and cout are used for input/output in C++.

Used By

Companies like Microsoft Windows Kernel, Telegram Messenger, Oracle Database, MySQL, etc.

 

Companies like Google Chrome, Microsoft Office, Torque 3-D game engine, etc.


Post a Comment

0 Comments

Ad Code