[email protected] +91 9175287066
This website is always under updation with new contents
C++ Language Tutorials
Introduction
C vs C++
Declaring Variable
Dynamic initialization of variable
Reference Variable
static Variables
static Local Variables
Assignment Operator
Arithmetic Operator
Conditional Operator
Relational Operator
Logical Operator
Increment/Decrement Operator
Bitwise Operator
new & delete operator
Manipulators
Precedence of Operators
Call by value
Call by address
Call by reference
Inline function
Default argument function
Function Overloading
Function inside class
Function outside class
Object array
Object as function arguments
Object memory allocation
Default constructor
Paramerised constructor
Copy constructor
Static member
Static Member Function
Unary Operator
Binary Operator
Single Inheritance
Multilevel Inheritance
Hierarchical Inheritance
Multiple Inheritance
Hybrid Inheritance
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.

Founder of C++ Language

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. Object
2. Class
3. Abstraction
4. Encapsulation
5. Inheritance
6. Overloading
7. Exception Handling
8. Message Passing
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.


Variable
Declaring Variable

As we know that, a variable is a named location in memory that is used to hold a value that may be modified by the program. All variables must be declared before they can be used.

We can declare variable in C++ anywhere in the scope just before the variable can in used.

Syntax:
	type variable_list;

Here, type must be a valid data type plus any modifiers, and variable_list may consist of one or more identifier names separated by commas.

Here are some declarations:
int i,j,l;
short int si;
unsigned int ui;
double balance, profit, loss;
e.g
#include<conio.h>
#include<iostream.h>
void main()
{
 	int n;
 	clrscr();
	 int sum=0;
	 for(int i=0;i<5;i++)
	 {
	    cout<<"\n Enter no ";
	    cin>>n;
	    sum+=n;
 	 }
 float avg=sum/5.0;
 cout<<"\n sum = "<<sum<<" avg = "<<avg;
 getch();
}
O/P
Enter no 1
Enter no 2
Enter no 3
Enter no 4
Enter no 5
Sum = 15
Avg = 30

Dynamic initialization of variable

C++ introduced dynamic initialization of variable in which value of expression must be initialize during declaration of variable.

e.g
#include<conio.h>
#include<iostream.h>
const int PI=3.1452;
void main()
{
 int r;
 clrscr();
 cout<<"\n Enter Redius ";
 cin>>r;
 float area=PI*r*r; // dynamic/runtime initialization or late binding
 cout<<"\n Area = "<<area;
 getch();
}
O/P
Enter  Redius
5
Area = 2625282560.000000

Reference Variable

C++ introduce new variable called reference variable. It is an alternate name or alias name for any variable.

Syntax:
	 & = 
e.g
int a=25;
	int &p=a;

static Variables

static variables are permanent variables within their own function or file. Unlike global variables, they are not known outside their function or file, but they maintain their values between calls.

This feature makes them useful when you write generalized functions and function libraries that other programmers may use.


static Local Variables

When you apply the static modifier to a local variable, the compiler creates permanent storage for it, much as it creates storage for a global variable.

The key difference between a static local variable and a global variable is that the static local variable remains known only to the block in which it is declared. In simple terms, a static local variable is a local variable that retains its value between function calls.


For accessing computer programs go to TECHNOLOGY