Wednesday, April 21, 2010

C vs. C++

Because of both it's low-level and high-level features, C++ is still one the most popular and widely-used language today. The high-level features were the result of enhancements to the earlier C thus retaining the low-level features. So if C++ is just an enhanced version of C, where do the differences lie? To answer this question, C++ was enhanced to exclude some of the C principles and to include some the features unknown to a C compiler.

Syntax Change

The first and very basic difference between the two languages is the slight change in syntax of some of the libraries.

Library & Linking

C++ has a larger library than C. For example, to compile a math-extensive program in gcc you have to separately link the math library for basic math functions in C. On the other hand you don't have to do explicit linking in C++.

Memory Allocation/DeAllocation

In C memory allocation for both arrays and elements is done through malloc. Also, inorder to deallocate the memory, it has to be done using free. In C++ memory allocation is done using new operator. Similarly, delete is used to free the memory.

Function Declaration

You need not explicitly declare a function in C. On the contrary, a C++ function need to be declared before use.

Structs

In C 'struct' keyword has to be explicitly included when declaring an instance. This has not to be done in C++.

Boolean Type

There is no primitive boolean data type in C. On the other hand, C++ has a primitive "bool" data type.

Library

The first and very basic difference between the two languages is the slight change in syntax of some of the libraries.

Summary

C++ could be seen as a better and more capable C in view of it's capability of having low-level and high-level features. 


0 comments:

Post a Comment

 

How to C++

Today there's 1000 many resources on C++ on the internet. 'How to C++' being one of them, provides you with easy to understand articles, tutorials and links on C++ fundamentals, STL, Win32 and MFC. Also find useful readings and tutorials on Data Structures, Algorithms and OpenGL in C++.

About Me

I am a Research Assistant at Concordia University, Montreal, Canada. I Teach C++ and OpenGL. Also I work as a freelance UI Researcher/Designer.
- Noorulain Khurshid

Followers

How to C++ Copyright © 2009 Blogger Template Designed by Bie Blogger Template
EasyHits4U.com - Your Free Traffic Exchange - 1:1 Exchange Ratio, 5-Tier Referral Program. FREE Advertising!