SlideShare a Scribd company logo
By………..
P.JEEVITHA(181604),
N.THARANI(181621),
II-B.SC MATHS(CA),
To
K.PADMAPRIYA M.SC;M.PHIL;
ASSISTENT PROFFESSOR,
DEPARTMENT OF MATHS(CA),
S.B.K.COLLEGE,
ARUPPUKOTTAI.
By………..
P.JEEVITHA(181604),
N.THARANI(181621),
II-B.SC MATHS(CA),
To
K.PADMAPRIYA M.SC;M.PHIL;
ASSISTENT PROFFESSOR,
DEPARTMENT OF MATHS(CA),
S.B.K.COLLEGE,
ARUPPUKOTTAI.
OVERLOADING BINARY OPERATORS USING FRIENDS:
Friend functions may be used in
the place of member functions for overloading a
binary operator,the only difference being that a friend
function requires two arguments to be explicitily
passed to it,while a member function requires only
one.
The complex number program discussed in the
previous section can be modified using a friend
operator function as follows:
❖ Replace the member function declaration by the
friend function declaration.
friend complex operator+(complex, complex);
❖ Redefine the operator function as follows:
Complex operator+(complex a, complex b)
{
return complex((a.x+b.x),(a.y+b.y));
}
MANIPULATION OF STRINGS USING OPERATORS:
ANSI C implements strings
using character arrays, pointers and string functions.
There are no operators for manipulating the strings.
For Example,
string3 =string1+string2;
if(string1 >= string2) string = string1;
Strings can be defined as class objects which
can be then manipulated like the built-in types.
Class string
{
char*p;
int len;
public:
………
………
};
SOME OTHER OPERATOR OVER LOADING EXAMPLES:
✓ Overloading the Subscript Operator[]
✓Overloading the Pointer-to-member(->) Operator
Overloading the Subscript Operator[]
The subscript operator is
normally used to access and modify a specific element
in an array.
Overloading the Pointer-to-member(->)Operator
The pointer-to-member operator
(->) is normally used in conjunction with an object
pointer to access any of the objects members.
RULES FOR OVERLOADING OPERATORS:
❖ Only existing operators can be overloaded . New operators
cannot be created.
❖ Overloaded operators follow the syntax rules of the
original operators.
❖ There are some operators that cannot be overloaded .
❖ We cannot use friend functions to overload certain
operators.
❖ Binary arithmetic operators such as +,-,*,and / must
explicitily return a value.
TYPE CONVERSIONS:
The type of data to the right of an assignment
operator is automatically converted to the type of the variable
on the left.
For Example,
int m;
float x=3.14159;
m=x;
Convert x to an integer before its value is assigned to
m.Thus, the fractional part is truncated.
The type conversions are automatic as long as the data types
involved are built-in types.
Three types of situations might arise in the data conversion
between uncompatible types:
❖ coversion from basic type to class type.
❖Conversion from class type to basic type.
❖Conversion from one class type to another class type.
BASIC TO CLASS TYPE:
The conversion from basic type to class is easy to
accomplish. It may be recalled that the use of constructors was
illustrated in a number of examples to inizialize objects.
string :: string (char*a)
{
length=strlen(a);
p=new char [length+1];
strcpy(p,a);
}
This construtor builds a string type object from a char* type
a.The variables length and p are data members of the class
string.
For Example,
string s1,s2;
char*name1=“IBM PC”;
char*name2= “Apple Computers”;
s1=string(name1);
s2=name2;
CLASS TO BASIC TYPE :
The constructors did a fine job in type conversion from
a basic to class type.
operator typename()
{
…………
…………(function statement)
}
This function converts a class type data to typename.
For Example,
The operator double() converts a class
object to type double,the operator int() converts a
class type object to type int,and so on.
vector :: operator double()
{
double sum=0;
for(int i=0;i<size;i++)
sum=sum+v[i]*v[i];
return sqrt(sum);
}
This function converts a vector to the
corresponding scalar magnitude.

More Related Content

What's hot

Type conversion
Type conversionType conversion
Type conversion
Frijo Francis
 
Chapter 2.datatypes and operators
Chapter 2.datatypes and operatorsChapter 2.datatypes and operators
Chapter 2.datatypes and operators
Jasleen Kaur (Chandigarh University)
 
C# operators
C# operatorsC# operators
Frequently asked questions in c
Frequently asked questions in cFrequently asked questions in c
Frequently asked questions in c
David Livingston J
 
1.1 and 1.2
1.1 and 1.21.1 and 1.2
1.1 and 1.2
wsnpky
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c language
Rai University
 
Frequently asked questions in c
Frequently asked questions in cFrequently asked questions in c
Frequently asked questions in c
David Livingston J
 
Module 3 : using value type variables
Module 3 : using value type variablesModule 3 : using value type variables
Module 3 : using value type variables
Prem Kumar Badri
 
Precedence and associativity (Computer programming and utilization)
Precedence and associativity (Computer programming and utilization)Precedence and associativity (Computer programming and utilization)
Precedence and associativity (Computer programming and utilization)
Digvijaysinh Gohil
 
C Structures And Unions
C  Structures And  UnionsC  Structures And  Unions
C Structures And Unions
Ram Sagar Mourya
 
Type conversion
Type  conversionType  conversion
Type conversion
PreethaPreetha5
 
C sharp_basic_ideas
C sharp_basic_ideasC sharp_basic_ideas
C sharp_basic_ideas
Ralph Weber
 
Cpu-fundamental of C
Cpu-fundamental of CCpu-fundamental of C
Cpu-fundamental of C
Suchit Patel
 
Concept of c data types
Concept of c data typesConcept of c data types
Concept of c data types
Manisha Keim
 
ECET350 Week 3 Homework Assignment
ECET350 Week 3 Homework AssignmentECET350 Week 3 Homework Assignment
ECET350 Week 3 Homework Assignment
BirleRubin
 
Step by step python(week2)
Step by step python(week2)Step by step python(week2)
Step by step python(week2)
Abhishek Jaiswal
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
programming9
 
Variable, constant, operators and control statement
Variable, constant, operators and control statementVariable, constant, operators and control statement
Variable, constant, operators and control statement
Eyelean xilef
 
C programming | Class 8 | III Term
C programming  | Class 8  | III TermC programming  | Class 8  | III Term
C programming | Class 8 | III Term
Andrew Raj
 
Basic Data Types in C++
Basic Data Types in C++ Basic Data Types in C++
Basic Data Types in C++
Hridoy Bepari
 

What's hot (20)

Type conversion
Type conversionType conversion
Type conversion
 
Chapter 2.datatypes and operators
Chapter 2.datatypes and operatorsChapter 2.datatypes and operators
Chapter 2.datatypes and operators
 
C# operators
C# operatorsC# operators
C# operators
 
Frequently asked questions in c
Frequently asked questions in cFrequently asked questions in c
Frequently asked questions in c
 
1.1 and 1.2
1.1 and 1.21.1 and 1.2
1.1 and 1.2
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c language
 
Frequently asked questions in c
Frequently asked questions in cFrequently asked questions in c
Frequently asked questions in c
 
Module 3 : using value type variables
Module 3 : using value type variablesModule 3 : using value type variables
Module 3 : using value type variables
 
Precedence and associativity (Computer programming and utilization)
Precedence and associativity (Computer programming and utilization)Precedence and associativity (Computer programming and utilization)
Precedence and associativity (Computer programming and utilization)
 
C Structures And Unions
C  Structures And  UnionsC  Structures And  Unions
C Structures And Unions
 
Type conversion
Type  conversionType  conversion
Type conversion
 
C sharp_basic_ideas
C sharp_basic_ideasC sharp_basic_ideas
C sharp_basic_ideas
 
Cpu-fundamental of C
Cpu-fundamental of CCpu-fundamental of C
Cpu-fundamental of C
 
Concept of c data types
Concept of c data typesConcept of c data types
Concept of c data types
 
ECET350 Week 3 Homework Assignment
ECET350 Week 3 Homework AssignmentECET350 Week 3 Homework Assignment
ECET350 Week 3 Homework Assignment
 
Step by step python(week2)
Step by step python(week2)Step by step python(week2)
Step by step python(week2)
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 
Variable, constant, operators and control statement
Variable, constant, operators and control statementVariable, constant, operators and control statement
Variable, constant, operators and control statement
 
C programming | Class 8 | III Term
C programming  | Class 8  | III TermC programming  | Class 8  | III Term
C programming | Class 8 | III Term
 
Basic Data Types in C++
Basic Data Types in C++ Basic Data Types in C++
Basic Data Types in C++
 

Similar to Operators in C++

Type conversion, precedence, associativity in c programming
Type conversion, precedence, associativity in c programmingType conversion, precedence, associativity in c programming
Type conversion, precedence, associativity in c programming
Dhrumil Panchal
 
CP Handout#3
CP Handout#3CP Handout#3
CP Handout#3
trupti1976
 
Chapter 13.1.2
Chapter 13.1.2Chapter 13.1.2
Chapter 13.1.2
patcha535
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
murugeswariSenthilku
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
Padma Kannan
 
Data Type Conversion in C++
Data Type Conversion in C++Data Type Conversion in C++
Data Type Conversion in C++
Danial Mirza
 
Function C programming
Function C programmingFunction C programming
Function C programming
Appili Vamsi Krishna
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
Asaye Dilbo
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
Pranali Chaudhari
 
Chapter 3.4
Chapter 3.4Chapter 3.4
Chapter 3.4
sotlsoc
 
Type Conversion, Precedence and Associativity
Type Conversion, Precedence and AssociativityType Conversion, Precedence and Associativity
Type Conversion, Precedence and Associativity
Aakash Singh
 
C UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDYC UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDY
Rajeshkumar Reddy
 
Mycasestudy
MycasestudyMycasestudy
Mycasestudy
Emmanuel college
 
Pointers
PointersPointers
Unit 4 functions and pointers
Unit 4 functions and pointersUnit 4 functions and pointers
Unit 4 functions and pointers
kirthika jeyenth
 
NIKUL SURANI
NIKUL SURANINIKUL SURANI
NIKUL SURANI
Nikul4470
 
FUNCTIONS IN C PROGRAMMING.pdf
FUNCTIONS IN C PROGRAMMING.pdfFUNCTIONS IN C PROGRAMMING.pdf
FUNCTIONS IN C PROGRAMMING.pdf
RITHIKA R S
 
Pointers operation day2
Pointers operation day2Pointers operation day2
Pointers operation day2
Bhuvana Gowtham
 
Function overloading
Function overloadingFunction overloading
Function overloading
Selvin Josy Bai Somu
 
3110003_PPS_GTU_Study_Material_Presentations_Unit-2_18122020041700AM (1).pptx
3110003_PPS_GTU_Study_Material_Presentations_Unit-2_18122020041700AM (1).pptx3110003_PPS_GTU_Study_Material_Presentations_Unit-2_18122020041700AM (1).pptx
3110003_PPS_GTU_Study_Material_Presentations_Unit-2_18122020041700AM (1).pptx
LeenaChaudhari24
 

Similar to Operators in C++ (20)

Type conversion, precedence, associativity in c programming
Type conversion, precedence, associativity in c programmingType conversion, precedence, associativity in c programming
Type conversion, precedence, associativity in c programming
 
CP Handout#3
CP Handout#3CP Handout#3
CP Handout#3
 
Chapter 13.1.2
Chapter 13.1.2Chapter 13.1.2
Chapter 13.1.2
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Data Type Conversion in C++
Data Type Conversion in C++Data Type Conversion in C++
Data Type Conversion in C++
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Chapter 3.4
Chapter 3.4Chapter 3.4
Chapter 3.4
 
Type Conversion, Precedence and Associativity
Type Conversion, Precedence and AssociativityType Conversion, Precedence and Associativity
Type Conversion, Precedence and Associativity
 
C UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDYC UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDY
 
Mycasestudy
MycasestudyMycasestudy
Mycasestudy
 
Pointers
PointersPointers
Pointers
 
Unit 4 functions and pointers
Unit 4 functions and pointersUnit 4 functions and pointers
Unit 4 functions and pointers
 
NIKUL SURANI
NIKUL SURANINIKUL SURANI
NIKUL SURANI
 
FUNCTIONS IN C PROGRAMMING.pdf
FUNCTIONS IN C PROGRAMMING.pdfFUNCTIONS IN C PROGRAMMING.pdf
FUNCTIONS IN C PROGRAMMING.pdf
 
Pointers operation day2
Pointers operation day2Pointers operation day2
Pointers operation day2
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
3110003_PPS_GTU_Study_Material_Presentations_Unit-2_18122020041700AM (1).pptx
3110003_PPS_GTU_Study_Material_Presentations_Unit-2_18122020041700AM (1).pptx3110003_PPS_GTU_Study_Material_Presentations_Unit-2_18122020041700AM (1).pptx
3110003_PPS_GTU_Study_Material_Presentations_Unit-2_18122020041700AM (1).pptx
 

More from Padma Kannan

B tree
B treeB tree
B tree
Padma Kannan
 
Java packags
Java packagsJava packags
Java packags
Padma Kannan
 
Java and c++
Java and c++Java and c++
Java and c++
Padma Kannan
 
Inheritance
InheritanceInheritance
Inheritance
Padma Kannan
 
Functions in c++,
Functions in c++,Functions in c++,
Functions in c++,
Padma Kannan
 
Functions of dbms
Functions  of dbmsFunctions  of dbms
Functions of dbms
Padma Kannan
 
Classes,object and methods java
Classes,object and methods javaClasses,object and methods java
Classes,object and methods java
Padma Kannan
 
Classes,object and methods jav
Classes,object and methods javClasses,object and methods jav
Classes,object and methods jav
Padma Kannan
 
Basic concept of oops
Basic concept of oopsBasic concept of oops
Basic concept of oops
Padma Kannan
 
LEARNING BASES OF ACTICITY
LEARNING BASES OF ACTICITYLEARNING BASES OF ACTICITY
LEARNING BASES OF ACTICITY
Padma Kannan
 
Social networking risks
Social networking risksSocial networking risks
Social networking risks
Padma Kannan
 
Inheritance
InheritanceInheritance
Inheritance
Padma Kannan
 
Excel2002
Excel2002Excel2002
Excel2002
Padma Kannan
 

More from Padma Kannan (13)

B tree
B treeB tree
B tree
 
Java packags
Java packagsJava packags
Java packags
 
Java and c++
Java and c++Java and c++
Java and c++
 
Inheritance
InheritanceInheritance
Inheritance
 
Functions in c++,
Functions in c++,Functions in c++,
Functions in c++,
 
Functions of dbms
Functions  of dbmsFunctions  of dbms
Functions of dbms
 
Classes,object and methods java
Classes,object and methods javaClasses,object and methods java
Classes,object and methods java
 
Classes,object and methods jav
Classes,object and methods javClasses,object and methods jav
Classes,object and methods jav
 
Basic concept of oops
Basic concept of oopsBasic concept of oops
Basic concept of oops
 
LEARNING BASES OF ACTICITY
LEARNING BASES OF ACTICITYLEARNING BASES OF ACTICITY
LEARNING BASES OF ACTICITY
 
Social networking risks
Social networking risksSocial networking risks
Social networking risks
 
Inheritance
InheritanceInheritance
Inheritance
 
Excel2002
Excel2002Excel2002
Excel2002
 

Recently uploaded

TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
Intelisync
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
Hiike
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
Dinusha Kumarasiri
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
HarisZaheer8
 

Recently uploaded (20)

TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
 

Operators in C++

  • 1. By……….. P.JEEVITHA(181604), N.THARANI(181621), II-B.SC MATHS(CA), To K.PADMAPRIYA M.SC;M.PHIL; ASSISTENT PROFFESSOR, DEPARTMENT OF MATHS(CA), S.B.K.COLLEGE, ARUPPUKOTTAI. By……….. P.JEEVITHA(181604), N.THARANI(181621), II-B.SC MATHS(CA), To K.PADMAPRIYA M.SC;M.PHIL; ASSISTENT PROFFESSOR, DEPARTMENT OF MATHS(CA), S.B.K.COLLEGE, ARUPPUKOTTAI.
  • 2. OVERLOADING BINARY OPERATORS USING FRIENDS: Friend functions may be used in the place of member functions for overloading a binary operator,the only difference being that a friend function requires two arguments to be explicitily passed to it,while a member function requires only one. The complex number program discussed in the previous section can be modified using a friend operator function as follows: ❖ Replace the member function declaration by the friend function declaration. friend complex operator+(complex, complex); ❖ Redefine the operator function as follows:
  • 3. Complex operator+(complex a, complex b) { return complex((a.x+b.x),(a.y+b.y)); } MANIPULATION OF STRINGS USING OPERATORS: ANSI C implements strings using character arrays, pointers and string functions. There are no operators for manipulating the strings. For Example, string3 =string1+string2; if(string1 >= string2) string = string1; Strings can be defined as class objects which can be then manipulated like the built-in types.
  • 4. Class string { char*p; int len; public: ……… ……… }; SOME OTHER OPERATOR OVER LOADING EXAMPLES: ✓ Overloading the Subscript Operator[] ✓Overloading the Pointer-to-member(->) Operator
  • 5. Overloading the Subscript Operator[] The subscript operator is normally used to access and modify a specific element in an array. Overloading the Pointer-to-member(->)Operator The pointer-to-member operator (->) is normally used in conjunction with an object pointer to access any of the objects members. RULES FOR OVERLOADING OPERATORS: ❖ Only existing operators can be overloaded . New operators cannot be created. ❖ Overloaded operators follow the syntax rules of the original operators.
  • 6. ❖ There are some operators that cannot be overloaded . ❖ We cannot use friend functions to overload certain operators. ❖ Binary arithmetic operators such as +,-,*,and / must explicitily return a value. TYPE CONVERSIONS: The type of data to the right of an assignment operator is automatically converted to the type of the variable on the left. For Example, int m; float x=3.14159; m=x; Convert x to an integer before its value is assigned to m.Thus, the fractional part is truncated.
  • 7. The type conversions are automatic as long as the data types involved are built-in types. Three types of situations might arise in the data conversion between uncompatible types: ❖ coversion from basic type to class type. ❖Conversion from class type to basic type. ❖Conversion from one class type to another class type. BASIC TO CLASS TYPE: The conversion from basic type to class is easy to accomplish. It may be recalled that the use of constructors was illustrated in a number of examples to inizialize objects. string :: string (char*a) { length=strlen(a); p=new char [length+1]; strcpy(p,a); }
  • 8. This construtor builds a string type object from a char* type a.The variables length and p are data members of the class string. For Example, string s1,s2; char*name1=“IBM PC”; char*name2= “Apple Computers”; s1=string(name1); s2=name2; CLASS TO BASIC TYPE : The constructors did a fine job in type conversion from a basic to class type. operator typename() { ………… …………(function statement)
  • 9. } This function converts a class type data to typename. For Example, The operator double() converts a class object to type double,the operator int() converts a class type object to type int,and so on. vector :: operator double() { double sum=0; for(int i=0;i<size;i++) sum=sum+v[i]*v[i]; return sqrt(sum); } This function converts a vector to the corresponding scalar magnitude.