Saturday 2 October 2010

Difference between c and c++


C
C++
C supports procedural programming paradigm for code development.
C++ supports both procedural and object oriented programming paradigms; therefore C++ is also called a hybrid language.
C does not support object oriented programming; therefore it has no support for polymorphism, encapsulation, and inheritance.
Being an object oriented programming language C++ supports polymorphism, encapsulation, and inheritance.
In C (because it is a procedural programming language), data and functions are separate and free entities.
In C++ (when it is used as object oriented programming language), data and functions are encapsulated together in form of an object. For creating objects class provides a blueprint of structure of the object.
In C, data are free entities and can be manipulated by outside code. This is because C does not support information hiding.
In C++, Encapsulation hides the data to ensure that data structures and operators are used as intended.
C, being a procedural programming, it is a function driven language.
While, C++, being an object oriented programming, it is an object driven language.
C does not allow functions to be defined inside structures.
In C++, functions can be used inside a structure.

C uses functions for input/output. For example scanf and printf.
C++ uses objects for input output. For example cin and cout.

C does not support reference variables.
C++ supports reference variables.
C has no support for virtual and friend functions.
C++ supports virtual and friend functions.
C provides malloc() and calloc() functions for dynamic memory allocation, and free() for memory de-allocation.
C++ provides new operator for memory allocation and free operator for memory de-allocation.
C does not provide direct support for error handling (also called exception handling)

C++ provides support for exception handling. Exceptions are used for "hard" errors that make the code incorrect.



1.      In Procedure Oriented Programming (POP) importance is given to the sequence of things to be done i.e. algorithms, where as in object Oriented Programming (OOP) importance is given to the data.
2.      In POP larger programs are divided into smaller programs called functions, where as in OOP larger programs are divided into objects.
3.      In POP, most functions share global data i.e. data moves freely around the system from function to function. In OOP mostly data is private and only functions inside the object can access the data i.e. data is secured.
4.      POP follows a top down approach in problem solving while OOP follows a bottom up approach.
5.      In POP adding of new data and new functions to existing data and functions is very difficult where as in OOP it is easy.
6.      In POP there are no access specifiers where as in OOP there are public, private and protected specifiers.
7.      In POP, operator cannot be overloaded and in OOP operator can be overloaded.
8.      Procedure Oriented programming creates a step by step program that guides the application through a sequence of instructions. Each instruction is executed in order.
9.      Object-Oriented programming is much more similar to the way the real world works; it is analogous to the human brain. Each program is made up of many entities called objects. Objects become the fundamental units and have behavior, or a specific purpose, associated with them.
10.  Objects cannot directly access another object’s data. Instead, a message must be sent requesting the data, just like people must ask one another for information; we cannot see inside each other’s heads. 
Benefits of Object-Oriented programming include: 
  1. Ability to simulate real-world events much more effectively.
  2. Code is reusable thus less code may have to be written.
  3. Data becomes active.
  4. Graphical User Interface (GUI) applications can be created effectively.
  5. Programmers are able to reach their goals faster.






Property
C
C++
Major Implementations:
GCC, MSVC, Borland C, Watcom C
GNU Compiler Collection, Microsoft Visual C++, Borland C++ Builder
Programming-input /output:
scanf for input;
printf for output
cin for input;
cout for output
Speed:
C applications are faster to compile and execute than C++ applications
C++ applications are generally slower at runtime, and are much slower to compile than C programs
Object Oriented Programming
No

Yes
Appeared in:
1972
1985
Designed by:
Dennis Ritchie
Bjarne Stroustrup
Typing Discipline:
Static, Weak
Static, Unsafe, Nominative
include:
use #include<stdio.h>
use #include <iostream.h>
String type:
Cannot use string type but declare it as an array
Can use string type
Classes:
No Classes but uses structures and unions
Uses classes and objects
Influenced:
awk, csh, C++, C#, Objective-C, BitC, D, Concurrent C, Java, JavaScript, Limbo, Perl, PHP
Ada 95, C#, Java, PHP, D, Aikido
Paradigms:
Imperative (procedural) systems implementation language
Multi-paradigm
Influenced by:
B (BCPL,CPL), ALGOL 68, Assembly
C, Simula, Ada 83, ALGOL 68, CLU, ML
Platforms:
Platform Dependent
Platform Independent



No comments:

Post a Comment