Custom Search

Friday 2 December 2011

Difference between c and c++, Where C and C++ Differ, 10 Major Differences Between C And C++, C & C++ in Details

Difference between c and c++, Where C and C++ Differ, 10 Major Differences Between C And C++, C & C++ in Details

1.C does not support new or delete commands. The memory operations to free or allocate memory in c are carried out by malloc() and free().


2. C follows the procedural programming paradigm while C++ is a multi-paradigm language(procedural as well as object oriented)

In case of C, importance is given to the steps or procedure of the program while C++ focuses on the data rather than the process.
Also, it is easier to implement/edit the code in case of C++ for the same reason.

3. In case of C, the data is not secured while the data is secured(hidden) in C++

This difference is due to specific OOP features like Data Hiding which are not present in C.

4. C is a low-level language while C++ is a middle-level language

C is regarded as a low-level language(difficult interpretation & less user friendly) while C++ has features of both low-level(concentration on whats going on in the machine hardware) & high-level languages(concentration on the program itself) & hence is regarded as a middle-level language.

5. C uses the top-down approach while C++ uses the bottom-up approach

6. Although most good C code will follow this convention, in C++ it is strictly enforced that all functions must be declared before they are used. This code is valid C, but it is not valid C++:
#include <stdio.h>
int main()
{
    foo();
    return 0;
}

int foo()
{
    printf( "Hello world" );
}

In case of C, the program is formulated step by step, each step is processed into detail while in C++, the base elements are first formulated which then are linked together to give rise to larger systems.

7. C is function-driven while C++ is object-driven

Functions are the building blocks of a C program while objects are building blocks of a C++ program.

8. C++ supports function overloading while C does not

Overloading means two functions having the same name in the same program. This can be done only in C++ with the help of Polymorphism(an OOP feature)

9. We can use functions inside structures in C++ but not in C.

In case of C++, functions can be used inside a structure while structures cannot contain functions in C.

10. The NAMESPACE feature in C++ is absent in case of C

C++ uses NAMESPACE which avoid name collisions.
For instance, two students enrolled in the same university cannot have the same roll number while two students in different universities might have the same roll number. The universities are two different namespace & hence contain the same roll number(identifier) but the same university(one namespace) cannot have two students with the same roll number(identifier)

11. The standard input & output functions differ in the two languages

C uses scanf & printf while C++ uses cin>> & cout<< as their respective input & output functions

12. C++ allows the use of reference variables while C does not

13. In c declaring the global variable several times is allowed but this is not allowed in c++.

14. main Doesn't Provide return 0 Automatically

In C++, you are free to leave off the statement 'return 0;' at the end of main; it will be provided automatically:
int main()
{
    printf( "Hello, World" );
}
but in C, you must manually add it:
int main()
{
    printf( "Hello, World" );
    return 0;
}

Laptops