Connect to

facebook google Email you tube you tube you tube
Theme images by MichaelJay. Powered by Blogger.

Projects

7.3.17

Major Differences between C and C++. When and Why to use C and C++



The basic and the most important difference between C and C++ is the C is a Procedural Programming language ie it is a function driven language, whereas talking about C++ it is Object Oriented Programming language or OOPs and so it is a combination of procedural as well as OOPs,

Talking in layman language
C++ supports the use of classes and everything is in the form of object and streams.
whereas C does not support the use of objects or classes.

Development 

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

    C++ was developed by Bjarne Stroustrup in 1979 with C++'s predecessor "C with Classes".

Also we can say that C is a subset of C++ where as C++ is a super set of C. Most programs of C can be executed in C++ where as Programs of C++ cannot be executed on C. By this i am not refering to the software or the compiler but the syntax. 

2. 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.

3. C does not support function and operator overloading.

     C++ supports both function and operator overloading.

4. C uses functions to perform input/output operations ie printf() and scanf() defined under      <stdio.h> 
     C++ uses objects or streams ie cin and cout to perform input/output operations defined          under <iostream.h>

5. In C we need format specifiers to display or read any information where as we dont need any such      specifiers in C++.

 EXAMPLE:

scanf("%d",&i);   
printf("%d",i); for integer data type in C.
where %d is the format specifier.

In C++ 
cin>>i;
cout<<i;

6. C provides malloc() and calloc() functions for dynamic memory allocation, and                   free() for memory de-allocation.
   
     C++ provides new operator for memory allocation and delete operator for memory de-           allocation.
7. This is also reflected in file handling. In case of C we use functions to perform i/o operations of files. Also we read data character wise, Whereas in C++ we use streams to perform i/o operations in files and can pass a complete object.

This comparison of C and C++ explains feature-wise difference between both programming languages. Please do write us if you have any suggestion/comment or come across any error on this page.

source: sumita arora text book and Let us C.

When and Why use C

 and C++

Well I came across this question " Why to learn C when it doesn't support features of C++?"

The answer to this as per me is:
I being a college student persuing the course BCA has learnt both C and C++. As everyone says that we should follow the steps and not jump the stairs similarly learning C first builds a strong base and a nice command over logic for learning any other programming languages.
Learning procedural programming first helps us to under stand concept of classes better. 

Designing any header file in the syntax of C is better.
Where as making a project using file handling C++ is much better and smoother too,

You can always design your own header file using C and use it further in C++.

No comments:
Write comments

Interested in our works and services?
Get more of our update !