Difference Between C and C++

25 October 2020 Posted by Arun 12 Min Read

Key Difference Between C and C++

The main difference between c and c++ is that c is a procedural programming language while c++ supports both procedural programming as well as object-oriented programming. C does not support the oops concepts like object and classes while c++ is an object driven language in which we can write a program using classes and objects.

History C and C++

C Language was developed and invented by Dennis MacAlistair Ritchie (An American Computer Scientist) in while C++ founder was Bjarne Stroustrup (A Danish computer scientist). C Language was invented in the year of 1972 at AT & T Bell Labs, USA while C++ invention starts from 1979. initially, it was C with classes but later in 1983, it was renamed as c++.

What is C?

Introduction of C

  • C is a general-purpose middle-level programming language.
  • It is developed by Dennis M. Ritchie at AT & T Bell Labs, the USA in 1972.
  • Initially, it was invented to develop UNIX Operating System.
  • C is the successor of BCPL(Basic combined programming language) also called B language.
  • In 1988 ANSI(American national standard institute) has formalized the C language.
  • Linux OS, PHP, MySQL are written in c language.

Uses of C

C is used to developing System applications as follows

  • Database System
  • Language Interpreters
  • Compiler and assemblers
  • Operating System
  • Network drivers
  • Word processor(eg: WYSIWYG editor(Bravo)=>What you See Is What you get)

Data Types in C

Data Types and Sizes in C

Type Size(In Bits) Size(In Bytes) Range
char 8 1 -128 to 127
unsigned char 8 1 0 to 255
int 16 2 -215 to 215-1
unsigned int 16 2 0 to 216-1
short int 8 1 -128 to 127
unsigned short int 8 1 0 to 255
long int 32 4 -231 to 231-1
unsigned long int 32 4 0 to 232-1
float 32 4 3.4E-38 to 3.4E+38
double 64 8 1.7E-308 to 1.7E+308
long double 80 10 3.4E-4932 to 1.1E+4932

Note: These sizes of data types might be differ from compiler to compiler.

What is C++?

Introduction of C++

  • C++ is a general-purpose and case sensitive programming language.
  • It is an object-oriented programming language.
  • It is an extension to C programming.
  • C++ developed by Bjarne Stroustrup.
  • C++ Invention starts in 1979 at Bell Labs.
  • It is considered a high-level language because it comprises(includes) a combination of both high-level and low-level language features.
  • It is enhanced c language and initially, it was C with Classes but later in 1983, it was renamed as c++.

Object-Oriented Programming (OOPs)

C++ supports the object-oriented programming, the four major pillar of object-oriented programming used in C++ are:

  1. Inheritance
  2. Polymorphism
  3. Encapsulation
  4. Abstraction

C++ Standard Libraries

Standard C++ programming is divided into three important parts:

  1. The core library includes the data types, variables and literals, etc.
  2. The standard library includes the set of functions manipulating strings, files, etc.
  3. The Standard Template Library (STL) includes the set of methods manipulating a data structure.

Usage of c++

By the help of C++ programming language, we can develop different types of secured and robust applications:

  • Windows application
  • Client-Server application
  • Device drivers
  • Embedded firmware etc

Features of C

  • It is a structured procedural programming language.
  • It supports modularity.
  • C is very fast and efficient.
  • It is a general-purpose programming language.
  • C is a middle-level language.
  • Rich Library with multiple functions.
  • C has a rich set of in-built operators.
  • It is easy to extend.
  • It supports pointers and memory management.
  • It is a portable programming language.
  • Varieties of data-types.
  • It is statically typed.
  • It is case sensitive programming language.
  • It is a platform-dependent language.
  • It is a compiler-based programming language.

Features of C

Features of C++

  • It is an object-oriented programming language.
  • It is a cross-platform or platform independent programming language.
  • It has a simple syntax.
  • C++ support dynamic memory allocations.
  • It is used to develop the Operating System.
  • C++ is a very popular programming language.
  • It is a high-level programming language.
  • It has portability.
  • C++ supports pointer and recursion.
  • It is a universal language.
  • C++ supports exception handling.
  • Templates are also available in c++.
  • C++ have data abstraction and data hiding feature.
  • It is enhanced C language.
  • It has operator-overloading and generic programming.

Features of C++

A Simple C and C++ Program Example

Note: We're doing programming on Turbo C++ IDE. If you want to download Turbo C++, click here

C Program

C++ Program

#include<stdio.h>
#include<conio.h>
main()
{
     clrscr();
     printf("Welcome to C Programming");
     getch();
}
#include<iostream.h>
#include<conio.h>
main()
{
     clrscr();
     cout<<"Welcome to C++ Programming";
     getch();
}
Output: Welcome to C Programming Output: Welcome to C++ Programming
Description of the C program
Description of the C++ program

# is a pre-processor which pre-process the file.

#include is a pre-processor directive tells the compile to include the contents of the specified header file.

stdio.h stands for Standard Input/Output Header File which contains all the I/O libraries functions that will be required during the compilation process.

conio.h stands for Console Input/Output Header File which contains all the Console libraries functions.

main() is the entry point of the program from where the execution of the program started. When C program is executed, the control immediately goes to the main() function.

{ } Braces are used to define the scope of a program.

clrscr() stands for Clear the Screen. This function exists in conio.h header file and used to clear the console screen(monitor).

; the semicolon is also called terminator and tells to program that the current statement has been terminated.

printf() function is used to print the data on the output screen.

getch() function is pre-defined in conio.h header file and used to hold the out screen until user press any character. It is stands for Get-a-character(getch).

# working is same as in c language.

#include works are same as in c language.

iostream.h stands for Input/Output Stream Header File which contains all the Objects like cin, cout, cerr and clog, etc that will be required during the compilation process.

conio.h works as c language conio.h works

main() function, A program execution always starts from main(). When the C++ program is executed, the control goes immediately to the main() function call.

{ } Braces are used to define the scope of a program in c++.

clrscr() stands for Clear the Screen in C++. This function exists in conio.h header file and used to clear the console screen(monitor).

cout stands for console output and used to print the data on console screen i.e. on the monitor. It is an instance of the Ostream class which exist in iostream.h header file.

>> is a stream insertion operator which is is used for output and extraction.

getch() function is a pre-defined function in conio.h header file which is used to hold the out screen until use press any character.

Comparison Between C and C++

C vs C++

Definition C is a general-purpose, mid-level, case-sensitive programming language which is developed by Denish M. Ritchie in 1972 at AT & T's Bell Labs USA. C++ is an Object-Oriented, high-level, case-sensitive programming language which is developed by Bjarne Stroustrup in 1979 at Bell Labs.
Programming Language C supports structured procedural programming. While C++ supports Object-Oriented programming.
Origin C language is based on assembly language. C++ is based on C language.
Subset C Programming is the subset of C++ programming. While C++ can run 99% of C programs but C can't run C++ programs.
Security In C language, data is less secure. While C++ is a highly secure language.
Keywords C has 32 keywords. C++ supports 63 keywords.
Memory Allocation C language supports malloc(), calloc(), realloc and for memory allocations and free() for memory de-allocation. While in C++ memory allocation is done by the new operator and delete operator is used for memory de-allocation.
Header Files C has stdio.h header file which library contains input and output functions. C++ has iostream.h header files which have two classes Istream and Ostream. cin is the instance of Istream while cout is the instance of Ostream class.
Approach C follows a top-down approach. While C++ follows bottom-approach.
Virtual Function C does not support virtual function. C++ supports both virtual and pure virtual function.
Operator Overloading Operator Overloading is not possible in C. C++ supports the feature of Operator Overloading.
main() call In C main() can be call from other functions. While in C++ main() can't be called from other functions.
Namespaces Not Available in C language. Namespaces are available in C++.
I/O Functions printf() and scanf() functions are used to take input and print the output on the console screen. cin and cout objects are used to take the input and print the output on the console screen.
Exception Handliing In C language there is no concept of exception handling. While it is the main feature of C++.
Inline Function C does not have an inline function. While C++ supports the inline function.
Generic Programming C does not support generic programming. It supports generic programming.
Inheritance Not supported in C language. Supported in C++.
Templates C language does support the feature of the template. While C++ supports it.
Data Hiding C does not support information hiding. While C++ encapsulation is used for data hiding.
Reference Variables Not supported in C. C++ supports the reference variables.
Global Variables Multiple declaration of global variables is allowed in C language. While C++ does not allow.
Mapping Mapping between data and function is difficult and complicated. While in C++ mapping can be used using "Objects".
Extension C language file extension is .c While C++ file extension is .cpp

Reference

ITianWorld


About author

Arun Kumar(Entrepreneur, Blogger, Thinker & SEO Expert)

Arun Kumar (Solopreneur, Blogger, Thinker & SEO Expert)

Hello, I'm Arun, Currently holding position as Head of Digital Marketing having 8+ years of experience. I specialize in lead generation through Facebook and Google Ads, as well as excelling in SEO, SMO, SEM, and SMM to craft captivating online presences. I'm driven by a strong sense of ownership, motivation, and an insatiable curiosity for learning. I orchestrate strategic promotions, measure KPIs, and craft compelling marketing campaigns. My email marketing strategies are designed to elevate brand visibility and product awareness. I'm also a dedicated mentor, guiding team leaders and executives to success. Let's connect and explore how I can add value to your digital marketing efforts.


Frequently Asked Questions

  • C is a structured programming language.
  • It is a general-purpose, middle-level programming language.
  • C is a compiler-based programming language.
  • C language has Rich Library with multiple functions.
  • It contains vast varieties of data-types.
  • C Programming supports modularity.
  • It is case sensitive language.
  • C language is very fast and efficient.
  • C language is easy to extend.
  • It is a platform-dependent programming language.

C language has some basic data types like char, int, float, and double and some modifiers data types like signed, unsigned, short and long.

exp++ also called post-increment which means "first execute the statement and then increment by 1" while ++exp also called pre-increment which means "increment by 1 first and then execute the statement".

There are 32 keywords in the c language.

malloc() or "memory allocation" and calloc() or "contiguous allocation" both functions are predifined function which exist in <stdlib.h> header file.

malloc() function is used to dynamically allocate a large block of memory with defined size and it returns a pointer type var(address of the memory location) while calloc() function is used to dynamically create the contiguous memory location.

malloc() function allocates only a single block of memory while calloc() allocates multiple blocks of memory.

memory allocated by malloc() contains the garbage values while calloc() initializes the allocated memory to zero.

Syntax of malloc(): type* ptr=malloc(sizeof(type));

Syntax of calloc(): ptr_name=(*cast type) calloc(no of blocks, sizeof(type));

C tokens are basic building blocks that are used to create the program. C tokens are Keywords, Constants, Identifiers, Strings, Special Symbol, Operators, Etc.

A preprocessor is a program that processes the c code before it passes through the compiler.

C language has many core concepts and data structures like arrays, strings, lists, functions, structure & union, etc. Since many languages follow the concept of c language and made after the c language introduced that so why c language is called the mother language of all languages.

printf() is used to print the data on the console screen while scanf() is used to take input from the user.

Dennis MacAlistair Ritchie (An American Computer Scientist) was the founder of the c language.

C++ founder was Bjarne Stroustrup (A Danish computer scientist).

cin and cout are objects. cin is the instance or object of Istream while cout is the instance or object of Ostream class.

OOPs stands for Object-Oriented Programming System.

  • Classes and Objects
  • Inheritance
  • Polymorphism
  • Abstraction
  • Encapsulation
  • Message Passing

C language supports structured procedural programming style While C++ Programming supports Object-Oriented Style.


Scroll to Top