KEY DIFFERENCE
- C is a Procedural Oriented language, whereas C++ is an Object-Oriented Programming language.
- C supports only Pointers whereas C++ supports both pointers and references.
- C does not allow you to use function overloading whereas C++ allows you to use function overloading.
- C supports built-in data types whereas C++ supports built-in as well as user-defined data types.
- C language follows the Top-Down programming approach whereas C++ follows a bottom-up programming approach.
- C scan and printf are used for the standard input and output while in C++, cin and cout are given for standard input and output operations.
Some other differences between C and ANSI C:
ANSI C allows the inclusion of a function prototype which gives the type of the function and the type of each parameter before defining the function.
In C, function declarations are assumed by default to be of type int. Hence, integer type functions need not declared at all.
In C, function headers have different syntax.
Function prototypes must be declared without a list of arguments and types, and consist of the type, function name and an empty set of parentheses.
C converts all float types in an expression to double precision types.
The type signed char is not available in C, but is in ANSI C.
In C, type void is not available.
In C, functions are assumed to return integer if they return nothing.
Many old C compilers expect that the first character of a preprocessor directive line is a #. No leading white space is allowed.
In C, the signed type qualifier is not available.
In C, the unsigned qualifier can be used to qualify integer types only.
In C, the unary positive sign is not allowed.
In C, the type long double is not available.
In C, the const qualifier is not available.
In C, enumeration type is not available.
Automatic arrays cannot be initialized in declarations in C. Only external and static arrays can be initialized.
Automatic structures and arrays of structures cannot be initialized in declarations in C.
In C, Some old compilers may not allow references to entire structures, requiring the use of structure pointers or individual structure members.
What is C programming language?
C is middle-level programming language which was developed at Bell Lab in 1972 by Dennis Ritchie. C language combines the features of Low level as well as High-level Language. Hence its considered a middle-level Language.
C is a high-level classical type programming language that allows you to develop firmware and portable applications. The C language was developed with an objective of writing system software. It is an ideal language for developing firmware systems.
What is C++ programming language?
C++ is a computer programming language that contains the feature of C programming language as well as Simula67( a first object Oriented language). C++ introduced the concept of Class and Objects.
It encapsulates high and low-level language features. So, it is seen as an intermediate level language. Earlier it was called "C with classes" as it had all the properties of the C language.
C Vs. C++: Key Differences
Basis of distinction | C | C++ |
---|---|---|
Programming type | It is a Procedural Oriented language. | It is an Object-Oriented Programming language. |
Approach | C language follows Top Down programming approach | C++ follow bottom-up programming approach. |
File extension | The file extension of a C program is .c | The file extension of a c+ + program language is.cpp |
Program division | In C programming language, a big program code is divided into small pieces which is called functions. | In C++ programming language, a big program code is divided into Objects and Classes. |
Structure | Structure in C not provide the feature of function declaration. | Structure in C++ provides the feature of declaring a function as a member function of the structure. |
Inline function | It does not allow inline function. | It supports inline function. |
Standard I/O operations | In C scan and printf are used for the standard input and output | In C++ cin» and cout« are given for standard input and output operations. |
Data Security | In C language the data is not secured. | Data is secure, so it can't be accessed by external functions. (Using Encapsulation concept of OOPs) |
Ease of Coding | C is an older programming language that is described as Hands-on. In this language, you must tell the program to do everything. Moreover, this language will let you do almost anything. | C++ is an extension language of C. It allows for the highly controlled object-oriented code. |
Compatibility with other languages | C is not compatible with another language. | C++ is compatible with the other generic programming languages. |
Pointer | C supports only Pointers. | C++ supports both pointers and references. |
Variable | In C, the variable should be defined at the beginning of the program. | C++ allows you to declare variables anywhere in the function. |
Point of Focus | C focuses on the steps or procedures that are followed to solve a problem. | C++ emphasizes the objects and not the steps or procedures. It has higher abstraction level. |
Function Overloading | C does not allow you to use function overloading. | C++ allows you to use function overloading. |
Data Types | C language does not allows you to declare String or Boolean data types. It supports built-in and primitive data types. | C++ supports String and Boolean data types. |
Exception Handling | C does not support Exception Handling. However, it can be performed using some workarounds. | C++ supports Exception handling. Moreover, this operation can be performed using try and catch block. |
Functions | Does not allows functions with default arrangements | Allow functions with default arrangements. |
Namespace | It is absent in C language. | It is present in the C++ language. |
Source Code | Free-format program source code. | Originally developed from the C programming language. |
Relationship | C is a subset of C++. It cannot run C++ code. | C++ is a superset of C. C++ can run most of C code while C cannot run C++ code. |
Driven by | Function-driven language | Object-driven language |
Focus | Focuses on method or process instead of data. | Focuses on data instead of method or procedure. |
Encapsulation | Does not support encapsulation. As Data and functions are separate and free entities. | Supports encapsulation. Data and functions are encapsulated together as an object. |
Information hiding | C does not support information hiding. In this language, data are free entities and can be changed outside code. | Encapsulation hides the data. So that data structures and operators are used as per intention. |
Memory management | C provide malloc() and calloc() functions for dynamic memory allocation. | C++ provides a new operator for this purpose. |
Data Types | Supports built-in data types. | Supports built-in & user-defined data types. |
Global Variables | Allows Multiple Declaration of global variables. | Multiple Declaration of global variables are not allowed. |
Concept of Mapping | The mapping between Data and Function is very complicated. | The mapping between Data and Function can be easily established using "Classes and Objects." |
Inheritance | Inheritance is not supported C | Inheritance is possible in C++ language. |
Default header file | C used stdio.h header file. | C++ uses iosteam.h as default header file. |
Virtual function | The concept of virtual Functions are present in C. | The concept of virtual Function is not used in C++. |
Keywords | Contain 32 keywords. | Contains 52 keywords. |
Polymorphism | In C. Polymorphism is not possible | The concept of polymorphism is used in C++. Polymorphism is one of the most Important Features of OOPS. |
GUI programming | C language offers GTK tool for GUI programming | C++ supports Qt tools for GUIprogramming |
Tags:
clanguage