SlideShare a Scribd company logo
Ashokrao Mane Group of
Institution’s
Department of Computer Science &Engineering
Sub-OOP
By
Prof.K.V.Rokade
 An operator is a symbol that tells the compiler
to perform specific mathematical or logical
manipulations. C++ is rich in built-in operators
and provide the following types of operators −
 Arithmetic Operators
 Relational Operators
 Logical Operators
 Bitwise Operators
 Assignment Operators
 Misc Operators
Operators in C++
Arithmetic Operators
There are following arithmetic operators supported by C++ language −
Assume variable A holds 10 and variable B holds 20, then −
Relational Operators
There are following relational operators supported by C++ language
Assume variable A holds 10 and variable B holds 20, then −
Logical Operators
There are following logical operators supported by C++ language.
Assume variable A holds 1 and variable B holds 0, then −
oprators in cpp,types with example and details.pptx
oprators in cpp,types with example and details.pptx
oprators in cpp,types with example and details.pptx
Misc Operators
 C++ allows you to specify more than one definition for a function name or
an operator in the same scope, which is called function
overloading and operator overloading respectively.
 An overloaded declaration is a declaration that is declared with the same name as
a previously declared declaration in the same scope, except that both declarations
have different arguments and obviously different definition (implementation).
 When you call an overloaded function or operator, the compiler determines the
most appropriate definition to use, by comparing the argument types you have
used to call the function or operator with the parameter types specified in the
definitions. The process of selecting the most appropriate overloaded function or
operator is called overload resolution.
 Function Overloading in C++
 You can have multiple definitions for the same function name in the same scope.
The definition of the function must differ from each other by the types and/or the
number of arguments in the argument list. You cannot overload function
declarations that differ only by return type.
 Following is the example where same function print() is being used to print
different data types −
C++ Overloading (Operator and Function)
oprators in cpp,types with example and details.pptx
 What is Operator Overloading?
 Using operator overloading in C++, you can
specify more than one meaning for an operator
in one scope. The purpose of operator
overloading is to provide a special meaning of
an operator for a user-defined data type.
 With the help of operator overloading, you can
redefine the majority of the C++ operators. You
can also use operator overloading to perform
different operations using one operator.
class class_name
{ ... .. ...
public
return_type operator symbol (argument(s))
{
... .. ...
}
... .. ...
};
syntax
#include <iostream.h>
#inlude<conio.h>
class TestClass {
private:
int count;
public:
TestClass()
{
count=5;
}
void operator --() {
count = count - 3;
}
void Display() {
cout << "Count: " << count; }
};
void main() {
TestClass tc;
--tc;
tc.Display();
getch();
}
Unary oprator overloading
No. There are C++ operators that can't be
overloaded.
They include:
 :: -Scope resolution operator
 ?: -ternary operator.
 . -member selector
 Sizeof operator
 * -member pointer selector
Can all C++ Operators be Overloaded?
 Type Conversion refers to conversion from one type to another. The main idea behind type
conversion is to make variable of one type compatible with variable of another type to
perform an operation. For example, to find the sum of two variables, one of int type & other
of float type. So, you need to type cast int variable to float to make them both float type for
finding the sum. In this blog we will learn how to perform type conversion in C++.
 In C++, there are two types of type conversion i.e. implicit type conversion & explicit type
conversion.
Implicit Type Conversion
 Implicit type conversion or automatic type conversion is done by the compiler on its own.
There is no external trigger required by the user to typecast a variable from one type to
another.
 This occurs when an expression contains variables of more than one type. So, in those
scenarios automatic type conversion takes place to avoid loss of data. In automatic type
conversion, all the data types present in the expression are converted to data type of the
variable with the largest data type.
 Below is the order of the automatic type conversion. You can also say, smallest to largest data
type for type conversion.
 bool -> char -> short int -> int -> unsigned int -> long -> unsigned -> long long -> float ->
double -> long double
 Implicit conversions can lose information such as signs can be lost when signed type is
implicitly converted to unsigned type and overflow can occur when long is implicitly
converted to float.
 Now let us look at an example to understand how implicit type conversion works in C++.
Type Conversion In C++
 #include <iostream.h>
 int main()
 {
 int int1 = 100; // integer int1
 char char1 = 'c'; // character char1
 // char1 implicitly converted to int using ASCII value of 'c' i.e. 99
 int1 = int1 + char1;
 // int1 is implicitly converted to float
 float flt1 = int1 + 2.7;
 cout << "int1 = " << int1 << endl
 << "char1 = " << char1 << endl
 << "flt1 = " << flt1 << endl;
 return 0;
 }
 Output
 int1 = 199
 char1 = c
 flt1 = 201.7
Implicit conversion program
Explicit Type Conversion
 Explicit type conversion or type casting is user defined type
conversion. In explicit type conversion, the user converts one type of
variable to another type. Explicit type conversion can be done in two
ways in C++:
 Converting by assignment
 Conversion using Cast operator
 Now let’s look at each of the ways to explicit type cast one type to
another.
1. Converting by assignment
 In this type conversion the required type is explicitly defined in front of
the expression in parenthesis. Data loss happens in explicit type
casting. It is considered as forceful casting. Let’s look at an example.
Type Conversion In C++
 #include <iostream>
 using namespace std;
 int main()
 {
 double dbl1 = 8.9;
 // Explicit conversion from double to int
 int res = (int)dbl1 + 1;
 cout << "Result = " << res;
 return 0;
 }
 Output
 Result = 9
Converting by assignment
2. Conversion using Cast Operator
 Cast operator is an unary operator which forces one data type to be converted into another data
type. There are four types of casting in C++, i.e. Static Cast, Dynamic Cast, Const Cast and
Reinterpret Cast.
#include <iostream.h>
int main()
{
float flt = 30.11;
// using cast operator
int int1 = static_cast<int>(flt);
cout <<int1;
}
Output
30
Conversion using Cast Operator

More Related Content

PDF
Basics _of_Operator Overloading_Somesh_Kumar_SSTC
PDF
Ch-4-Operator Overloading.pdf
PDF
Operator overloading
PDF
Operator_Overloaing_Type_Conversion_OOPC(C++)
PDF
NIKUL SURANI
PPTX
Operator overloading
PPTX
Operator Overloading
PPTX
Operator overloaing
Basics _of_Operator Overloading_Somesh_Kumar_SSTC
Ch-4-Operator Overloading.pdf
Operator overloading
Operator_Overloaing_Type_Conversion_OOPC(C++)
NIKUL SURANI
Operator overloading
Operator Overloading
Operator overloaing

Similar to oprators in cpp,types with example and details.pptx (20)

PDF
Object Oriented Programming using C++ - Part 3
PDF
(Polymorphism-OperatorOverLoadingUsingFriendFunction).pdf
PPT
Lec 26.27-operator overloading
PPT
3d7b7 session4 c++
PPTX
Lecture 2 variables
PPTX
operator overloading
PPTX
Operator overloading2
PPT
Lec 28 - operator overloading
PPTX
3. Polymorphism.pptx
PDF
Unit3_OOP-converted.pdf
PDF
Polymorphism and Type Conversion.pdf pot
PPTX
Type conversion
PDF
M11 operator overloading and type conversion
PPT
Unary operator overloading
PPTX
B.sc CSIT 2nd semester C++ Unit4
PPT
OOP in C++
PDF
OOP UNIT 1_removed ppt explaining object.pdf
PPTX
Data Type Conversion in C++
PDF
overloading in C++
Object Oriented Programming using C++ - Part 3
(Polymorphism-OperatorOverLoadingUsingFriendFunction).pdf
Lec 26.27-operator overloading
3d7b7 session4 c++
Lecture 2 variables
operator overloading
Operator overloading2
Lec 28 - operator overloading
3. Polymorphism.pptx
Unit3_OOP-converted.pdf
Polymorphism and Type Conversion.pdf pot
Type conversion
M11 operator overloading and type conversion
Unary operator overloading
B.sc CSIT 2nd semester C++ Unit4
OOP in C++
OOP UNIT 1_removed ppt explaining object.pdf
Data Type Conversion in C++
overloading in C++
Ad

Recently uploaded (20)

PPTX
Construction Project Organization Group 2.pptx
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Geodesy 1.pptx...............................................
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPTX
CH1 Production IntroductoryConcepts.pptx
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
Well-logging-methods_new................
PPT
Mechanical Engineering MATERIALS Selection
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
OOP with Java - Java Introduction (Basics)
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
Welding lecture in detail for understanding
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Construction Project Organization Group 2.pptx
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Geodesy 1.pptx...............................................
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
CH1 Production IntroductoryConcepts.pptx
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
R24 SURVEYING LAB MANUAL for civil enggi
Operating System & Kernel Study Guide-1 - converted.pdf
Well-logging-methods_new................
Mechanical Engineering MATERIALS Selection
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Internet of Things (IOT) - A guide to understanding
OOP with Java - Java Introduction (Basics)
Model Code of Practice - Construction Work - 21102022 .pdf
Welding lecture in detail for understanding
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Ad

oprators in cpp,types with example and details.pptx

  • 1. Ashokrao Mane Group of Institution’s Department of Computer Science &Engineering Sub-OOP By Prof.K.V.Rokade
  • 2.  An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. C++ is rich in built-in operators and provide the following types of operators −  Arithmetic Operators  Relational Operators  Logical Operators  Bitwise Operators  Assignment Operators  Misc Operators Operators in C++
  • 3. Arithmetic Operators There are following arithmetic operators supported by C++ language − Assume variable A holds 10 and variable B holds 20, then −
  • 4. Relational Operators There are following relational operators supported by C++ language Assume variable A holds 10 and variable B holds 20, then −
  • 5. Logical Operators There are following logical operators supported by C++ language. Assume variable A holds 1 and variable B holds 0, then −
  • 10.  C++ allows you to specify more than one definition for a function name or an operator in the same scope, which is called function overloading and operator overloading respectively.  An overloaded declaration is a declaration that is declared with the same name as a previously declared declaration in the same scope, except that both declarations have different arguments and obviously different definition (implementation).  When you call an overloaded function or operator, the compiler determines the most appropriate definition to use, by comparing the argument types you have used to call the function or operator with the parameter types specified in the definitions. The process of selecting the most appropriate overloaded function or operator is called overload resolution.  Function Overloading in C++  You can have multiple definitions for the same function name in the same scope. The definition of the function must differ from each other by the types and/or the number of arguments in the argument list. You cannot overload function declarations that differ only by return type.  Following is the example where same function print() is being used to print different data types − C++ Overloading (Operator and Function)
  • 12.  What is Operator Overloading?  Using operator overloading in C++, you can specify more than one meaning for an operator in one scope. The purpose of operator overloading is to provide a special meaning of an operator for a user-defined data type.  With the help of operator overloading, you can redefine the majority of the C++ operators. You can also use operator overloading to perform different operations using one operator.
  • 13. class class_name { ... .. ... public return_type operator symbol (argument(s)) { ... .. ... } ... .. ... }; syntax
  • 14. #include <iostream.h> #inlude<conio.h> class TestClass { private: int count; public: TestClass() { count=5; } void operator --() { count = count - 3; } void Display() { cout << "Count: " << count; } }; void main() { TestClass tc; --tc; tc.Display(); getch(); } Unary oprator overloading
  • 15. No. There are C++ operators that can't be overloaded. They include:  :: -Scope resolution operator  ?: -ternary operator.  . -member selector  Sizeof operator  * -member pointer selector Can all C++ Operators be Overloaded?
  • 16.  Type Conversion refers to conversion from one type to another. The main idea behind type conversion is to make variable of one type compatible with variable of another type to perform an operation. For example, to find the sum of two variables, one of int type & other of float type. So, you need to type cast int variable to float to make them both float type for finding the sum. In this blog we will learn how to perform type conversion in C++.  In C++, there are two types of type conversion i.e. implicit type conversion & explicit type conversion. Implicit Type Conversion  Implicit type conversion or automatic type conversion is done by the compiler on its own. There is no external trigger required by the user to typecast a variable from one type to another.  This occurs when an expression contains variables of more than one type. So, in those scenarios automatic type conversion takes place to avoid loss of data. In automatic type conversion, all the data types present in the expression are converted to data type of the variable with the largest data type.  Below is the order of the automatic type conversion. You can also say, smallest to largest data type for type conversion.  bool -> char -> short int -> int -> unsigned int -> long -> unsigned -> long long -> float -> double -> long double  Implicit conversions can lose information such as signs can be lost when signed type is implicitly converted to unsigned type and overflow can occur when long is implicitly converted to float.  Now let us look at an example to understand how implicit type conversion works in C++. Type Conversion In C++
  • 17.  #include <iostream.h>  int main()  {  int int1 = 100; // integer int1  char char1 = 'c'; // character char1  // char1 implicitly converted to int using ASCII value of 'c' i.e. 99  int1 = int1 + char1;  // int1 is implicitly converted to float  float flt1 = int1 + 2.7;  cout << "int1 = " << int1 << endl  << "char1 = " << char1 << endl  << "flt1 = " << flt1 << endl;  return 0;  }  Output  int1 = 199  char1 = c  flt1 = 201.7 Implicit conversion program
  • 18. Explicit Type Conversion  Explicit type conversion or type casting is user defined type conversion. In explicit type conversion, the user converts one type of variable to another type. Explicit type conversion can be done in two ways in C++:  Converting by assignment  Conversion using Cast operator  Now let’s look at each of the ways to explicit type cast one type to another. 1. Converting by assignment  In this type conversion the required type is explicitly defined in front of the expression in parenthesis. Data loss happens in explicit type casting. It is considered as forceful casting. Let’s look at an example. Type Conversion In C++
  • 19.  #include <iostream>  using namespace std;  int main()  {  double dbl1 = 8.9;  // Explicit conversion from double to int  int res = (int)dbl1 + 1;  cout << "Result = " << res;  return 0;  }  Output  Result = 9 Converting by assignment
  • 20. 2. Conversion using Cast Operator  Cast operator is an unary operator which forces one data type to be converted into another data type. There are four types of casting in C++, i.e. Static Cast, Dynamic Cast, Const Cast and Reinterpret Cast. #include <iostream.h> int main() { float flt = 30.11; // using cast operator int int1 = static_cast<int>(flt); cout <<int1; } Output 30 Conversion using Cast Operator