Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +917541905230, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Thursday, June 10, 2021

Difference between C and C++

C is a procedural programming language and does not support classes and objects, while C++ is a combination of both procedural and object-oriented.

Difference between C and C++ | welcome2protec
Difference between C and C++ | welcome2protec

What is difference between C and C++?

The main difference between both these languages is that, C is a procedural programming language and does not support classes and objects, while C++ is a combination of both procedural and object-oriented programming languages. On the other hand, C++ supports both procedural and object-oriented programming paradigms.

Here is the some differences between C and C++ are:

  • In C, for input or output, we use functions like gets(), puts(), scanf(), printf(), etc. These functions expect values to be of a particular data type, or in the case of scanf() or printf(), we have to specify the data type we want the function to process. In C++, we can and sometimes do use these functions. However, people generally prefer using the objects cin and cout. Note that these are objects of a class, and when we perform I/O, these themselves determine the data type of the variable.

  • C does not support function overloading. You cannot have multiple functions with the same name. So suppose you have a function which calculates the square of an integer number and a function to calculate the square of a floating point number, you have to give them separate names. In C++, give them the same name, and the language will determine which function to use depending on the types of parameters passed to the function.

  • C does not support exception handling. You are supposed to prevent conditions which lead to a runtime error due to some unexpected turn of events. In C++, you can throw exceptions and handle them accordingly. This is extremely useful when making large projects.

  • Besides function overloading, C++ also supports operator overloading not present in C. Ever wanted to concatenate two strings with the + operator? Well, tough luck with C, but with C++, you can do that. Of course, classes make it all possible, and you have to use std::string instead of regular strings, but then, std::string is much better for sanity.

  • And the previous point brings us to this, std::string. This is a (surprise, surprise) class, for strings. Much easier to use and read than C style strings.

  • For dynamic memory allocation, C uses malloc() and free(), but C++ has new and delete operators which are much better.

  • Namespaces are getting popular, especially in application development, and C++ does have support for namespaces, which is lacking in C.

  • An annoying feature of C is that you need to declare all your variables at the start of their scope, i.e, right after the opening brace of the block or function. In C++, define an variable anywhere, preferably closest to where it is used.

  • In C, your global variables can have multiple declarations. C++ is stricter, it doesn't allow this.

  • C++, after all, is object oriented. Things like abstraction, inheritance, polymorphism, cannot be done in C. It brings into your hands a whole new paradigm. Use it if you like it. If not, you can make do without it (but a lot of features of C++ are built around classes).

  • Ever wanted to create similar functions differing only in the data types they deal with? You can do it with function overloading, but that is generally used for function with the same name but different behavior. What if you want to do exactly the same thing, but for different data types? It doesn't make a lot of sense to write multiple functions for it. And function overloading does not support functions differing only by return type. Here is where templates come in. You can create generic functions and classes and use them with any data type. C++ has it, C doesn't.

  • C++ has STL (Standard Templeted Library), an extremely useful list of templated classes (so you can use them with a variety of data types). The Standard Temlated Library is a software library for the C++ programming language that influenced many parts of the C++ Standard Library. It provides four components called algorithms, containers, functions, and iterators.

Waht was C++ initially called and why it's named C++?

C++ was originally called 'C with classes,' and was built as an extension of the C language. Its name reflects its origins, C++ literally means 'increment C by 1.' It was renamed C++ in 1983, but retains a strong link to C, and will compile most C programs






Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Help others by sharing this page.

Ahmad Irshad

Author & Editor

I love blogging, teaching, learning computer science and sharing it to others. I've written and develped this site so that students may learn computer science related tutorials eaisly. MCA / MCITP

0 Comments:

Post a Comment

Please don't enter any spam link in the comment box.


Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec
Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec
Contact Us