Image

C++ - Introduction to C++ - Introduction

C++ Programming Language

Introduction

C++ is an object oriented programming language which supports all the features provided by object oriented methodology. C++ was developed in AT & T Bell laboratory in early 1980’s by Bjarne Stroustrup. Initially C++ was named C with classes. Later it’s name changed to C++. The idea of C++ comes from C’s increment operator ++. All C programs are C++ programs that is all C programs can run within C++ environment.

C is as it is in C++ but additional C does not have security but C++ have.

1560580276-image.png

Difference between C and C++

Difference between C and C++
No.C Language C++ Language
1)C is Procedural Language.C++ is non Procedural i.e Object oriented Language.
2)No virtual Functions are present in CThe concept of virtual Functions are used in C++.
3)In C, Polymorphism is not possible.The concept of polymorphism is used in C++.
4)Operator overloading is not possible in C.Operator overloading is one of the greatest Feature of C++.
5)Top down approach is used in Program Design.Bottom up approach adopted in Program Design.
6)No namespace Feature is present in C Language.Namespace Feature is present in C++ for avoiding Name collision.
7)Multiple Declarations of global variables are allowed.Multiple Declarations of global variables are not allowed.
8)In C
• scanf() Function used for Input.
• printf() Function used for output.
In C++
• Cin>> Function used for Input.
• Cout<< Function used for output.
9)Mapping between Data and Function is difficult and complicated.Mapping between Data and Function can be used using "Objects"
10)In C, we can call main() Function through other FunctionsIn C++, we cannot call main() Function through other functions.
11)C requires all the variables to be defined at the starting of a scope.C++ allows the declaration of variable anywhere in the scope i.e at time of its First use.
12)No inheritance is possible in C.Inheritance is possible in C++
13)In C, malloc() and calloc() Functions are used for Memory Allocation and free() function for memory deallocating.In C++, new and delete operators are used for memory allocating and deallocating.
14)It supports built-in and primitive data typesIt support both built-in and user define data types
15) In C, Exception Handling is not present.In C++, Exception Handling is done with Try and Catch block.

Object Oriented Programming Features

  1. 1.Object
  2. 2.Class
  3. 3.Abstraction
  4. 4.Encapsulation
  5. 5.Inheritance
  6. 6.Overloading
  7. 7.Exception Handling
  8. 8.Message Passing
  9. 9.Dynamic Binding

Object

Objects are the basic unit of OOP. They are instances of class, which have data members and use various member functions to perform tasks.

Class

It is similar to structures in C language. Class can also be defined as user defined data type but it also contains functions in it. So, class is basically a blueprint for object. It declares & defines what data variables the object will have and what operations can be performed on the class's object.

Abstraction

Abstraction refers to showing only the essential features of the application and hiding the details. In C++, classes provide methods to the outside world to access & use the data variables, but the variables are hidden from direct access. This can be done access specifiers.

Encapsulation

It can also be said data binding. Encapsulation is all about binding the data variables and functions together in class.

Inheritance

Inheritance is a way to reuse once written code again and again. The class which is inherited is called base calls & the class which inherits is called derived class. So when, a derived class inherits a base class, the derived class can use all the functions which are defined in base class, hence making code reusable.

Polymorphism

It is a feature, which lets us create functions with same name but different arguments, which will perform differently. That is function with same name, functioning in different way. Or, it also allows us to redefine a function to provide its new definition. You will learn how to do this in details soon in coming lessons.

Exception Handling

Exception handling is a feature of OOP, to handle unresolved exceptions or errors produced at runtime.

Message Passing

Message Passing is nothing but sending and receiving of information by the objects same as people exchange information. So this helps in building systems that simulate real life. Following are the basic steps in message passing.

•Creating classes that define objects and its behavior.

•Creating objects from class definitions.

•Establishing communication among objects.

In OOPs, Message Passing involves specifying the name of objects, the name of the function, and the information to be sent.

Dynamic Binding

Dynamic Binding refers to linking a procedure call to the code that will be executed only at run time. The code associated with the procedure in not known until the program is executed, which is also known as late binding.