DEV Community

Cover image for C Vs C++
Jagroop Singh
Jagroop Singh

Posted on

C Vs C++

C and C++ are both programming languages, but they were designed for different purposes and have some key differences.
Here are a few of the main differences between C and C++:

1)C++ is an object-oriented programming (OOP) language, while C is a procedural language. This means that C++ provides support for classes, objects, and other OOP concepts, while C does not.

2)C++ includes features for exception handling, such as try-catch blocks, which are not present in C.

3)C++ allows function overloading, which means that multiple functions can have the same name as long as they have different argument lists. C does not support function overloading.

4)C++ has a constexpr keyword that allows you to define variables that are evaluated at compile-time, rather than at runtime. C does not have this feature.

5)C++ supports function templates, which allow developers to write generic functions that can work with a variety of data types. C does not have this feature.

6) C++ supports reference variables, which are an alternative to pointers that allow developers to more easily manipulate memory addresses. C does not have reference variables.

7) C++ has a more powerful type system than C, with features such as class inheritance and virtual functions.
C++ includes support for the standard template library (STL), a collection of pre-built data structures and algorithms that can be used in C++ programs. C does not have this feature.

8) C++ supports namespaces, which allow developers to group related code and avoid naming conflicts. C does not have this feature.

9) C++ has improved support for object-oriented programming, with features such as polymorphism and inheritance. C does not have these features.

10) C++ includes a number of additional operators and syntax elements that are not present in C, such as the "::"(scope resolution) operator for accessing a global variable when there is a local variable with same name.

11)C++ introduces the new and delete operators for allocating and deallocating memory dynamically. C does not have these operators and relies on manual memory management using functions such as malloc() and free().

Despite these differences, C++ is based on C and many C programs can be easily adapted to C++ by adding object-oriented features. However, the reverse is not true: C++ code may not be compatible with C compilers and may require significant modification to work in a C environment.

Top comments (7)

Collapse
 
pauljlucas profile image
Paul J. Lucas

4) C++ has a more flexible syntax than C, with features such as default function arguments and inline functions.

C also supports inline functions.

10) C++ includes a number of additional operators and syntax elements that are not present in C, such as the "->" operator for accessing class members through pointers.

C also has the -> operator. C++ inherited it from C!

11) C++ allows developers to use inline functions

This is redundant with (4).

Please fact-check.

Collapse
 
jagroop2001 profile image
Jagroop Singh

HI @pauljlucas !!
I have verified the points and you are correct . Thanks for letting me know.

I have Replaced the that Points with new one.

Collapse
 
jagroop2001 profile image
Jagroop Singh

Hi @pauljlucas !!
Let me verify these from my end. If it is incorrect I will correct it . Thanks for Pointing out !!

Collapse
 
albertogato profile image
Alberto Gato Otero

10) is not true. The "->" operator is included in C, and can be used to access struct members through pointers.

Collapse
 
jagroop2001 profile image
Jagroop Singh

Hi @albertogato !!
I have verified the points and you are correct . Thanks for letting me know.

I have Replaced the that Points with new one.

Collapse
 
jagroop2001 profile image
Jagroop Singh

Hi @albertogato
Let Me
verify these from my end. If it is incorrect I will correct it . Thanks for Pointing out !!

Collapse
 
works profile image
Web

Insightful !!