C Vs C++ – 3 Major differences with explanation

(Last Updated On: November 5, 2016)

Interview Question C Vs C++ – What is difference between C and C++ language? For this question, we need answer 3 major differences with explanations.

Answer:

  • C is the procedural language whereas C++ is Object Oriented. Also, we can say, C is function driven program whereas C++ is object driven.
  • C lacks of features like extendibility (Inheritance) and simplicity (polymorphism) etc.
  • In C data is not secured where as in C++ is secure.

 

Detail of above difference between C and C++

Point -1: C is procedural language/function driven.  C++ is Object Oriented.

 

In C, starting from main(), step by step execution happens and all the functions are called in top to bottom approach. We create a list of functions with different header files if we want to keep group of functions in a separate files and include them in main program for executions. That why we called c as a function driven program.

 

 

C++ is Object oriented Program. In C++, functions are called using class objects. And hence called object oriented program.

 

 

Point -2: C lacks of features like Inheritance and polymorphism etc.
C does not support classes and objects. So, Inheritance or extendibility  or polymorphism is not possible in C but in C++.
Inheritance:

 

Polymorphism:

 

 

Point-3: In C, data is not secured where as in C++ it is secure.

Data is not secured in C.  For example, In below C program, variable int a can be accessed by any function e.g. func1 & func2. We cannot block access of variable a in a specific function.

 

 

Data can be protected in C++. For example, using access specifier private, protected or public etc. or provide the access of private data using public function etc.

In below C++ program example, if we don’t want Robot class to share variable a with derived class Human, we can control it with private specifier and if we want to give access to derived class Human only not outside of class for example in main() we can make variable a protected. If we want to give access to all we can make it public etc.

 

 

More Points on C Vs C++:

Above points are major differences between C and C++ language that we should answer in an interview. There could be more major points.

However if you want to go for feature and syntax  c and c++ differences, you could dive deeper for . for example –

  • Cin, cout is available in c++ not in C
  • No virtual function are available in c but in C++
  • Operator overloading is not possible in c
  • New and delete operators are available in C++ not in C
  • Exception handling is supported in C++ only
  • C does not support namespace.

Etc.