SlideShare a Scribd company logo
2
Most read
9
Most read
12
Most read
Object-Oriented
Programming in C+
        +
    Presented by Sachin Sharma
Operators in C++
• The symbols that are used in C++
  programs to form an expression are
  known as operators. C++ has a rich set
  of operators including all C language’s
  operators and also some new operators.
  There are three categories of operators in
  C++. These are:
• Unary Operators
• Binary Operators
• Ternary Operators
Unary Operators
• The operators that operate a single
  operand to form an expression are known
  as unary operators. The operators like +
  + (increment) operator, -- (decrement)
  operator etc. are the part of unary
  operators.
Binary Operators
• The operators that operate two or more
  operands are known as binary operators.
  The operators like +, -, *, /, % etc. are
  binary operators.
• E.g. a+b, a-b, a*b, a/b etc.
Ternary Operators
• The operator that operates minimum or
  maximum three operands is known as
  ternary operator. There is only one
  ternary operator available in C++. The
  operator ?: is the only available ternary
  operator i.e. used as a substitute of if-else
  statement.
• E.g. a>b ? a:b
Types of Operators in C++
•   Arithmetic operators
•   Logical operators
•   Comparison operators
•   Assignment operators
•   Bitwise operators
•   Scope resolution operator (::)
•   Line feed operator
•   Field width operator
Arithmetic Operators
• The operators that helps the programmer
  in mathematical calculations are known as
  arithmetic operators. Arithmetic
  operators include (+) for addition, (-) for
  subtraction, (/) for division, (*) for
  multiplication etc.
• E.g. 2+5 = 7
Logical Operators
• The operators that help the programmer to
  connect (combine) two or more
  expressions, are known as logical
  operators. Logical operators include:
1. &&          logical AND
2. | |         logical OR
3. |           logical NOT
Comparison Operators
•  The operators that are used to compare
   variables to check if they are similar or
   not. It will return values in true or false.
   These are also known as relational
   operators. Comparison operators are:
1. >       Greater than
2. <       Less than
3. =       Equal to
Assignment Operators
• The operator i.e. used to assign values to
  identifiers, is known as assignment
  operator. There is only one assignment
  operator in C++. The assignment operator
  (=) is used to assign values to identifiers.
• E.g.      a = 2 [ assign value 2 to a ]
Bitwise Operator
• The operators which operate a bit level
  and allows the programmer to manipulate
  individual bits. These are basically used
  for testing or shifting bits.
• E.g.      x << 3     // Shift three bit position
  to left
Scope Resolution Operator (::)
• Like C, C++ is also a block-structured
  language. A variable declared in a block is
  said to be local to that block. In C, the
  global version of a variable cannot be
  accessed from within the inner block. C++
  solves this problem by introducing the new
  operator :: called the scope resolution
  operator. This operator allows access to
  the global version of a variable.
Example to use the Scope
              Resolution Operator
•   // Program to demonstrate the use of scope resolution operator
    #include<iostream.h>
    #include<conio.h>
    int x = 10;        // global x
    int main()
    {
           int x = 20;             // x redeclared, local to main
           {
                       int k = x;
                       int x = 30;            // x is declared again in inner block
                       clrscr();
                       cout << “n We are in inner block n”;
                       cout << “k = “ << k << “n”;
                       cout << “x = “ << x <<“n”;
                       cout << “:: x = “ << :: x <<“n”;
           }
           cout << “n We are in outer block n”;
           cout << “x = “ << x <<“n”;
           cout << “:: x = “ << :: x <<“n”;
    return 0;
    }
Output
• We are in inner block
  k = 20
  x = 30
  :: x = 10

• We are in outer block
  x = 20
  :: x = 10
Line Feed Operator & Field Width
            Operator

• These operators are used to format data
  display. The most commonly used
  manipulators are endl and setw.
• The endl manipulator has the same effect
  as using the newline character “n”.
• The setw manipulator specifies a field
  width for printing the value of variables.
Example to use setw and endl
              operators
• // Program to demonstrate use of endl and setw operators
  #include<iostream.h>
  #include<conio.h>
  #include<iomanip.h>           // for setw
  int main()
  {
  int basic = 750, allowance = 75;
  clrscr();
  cout<< “Enter Basic Salary” << setw(10) <<basic<<endl;
  cout<<“Enter Allowance” << setw(10) <<allowance<<endl;
  return 0;
  }
Output
Enter Basic Salary   750
Enter Allowance      75
Thank You

More Related Content

What's hot (20)

PPTX
classes and objects in C++
HalaiHansaika
 
PPTX
Operators and expressions in C++
Neeru Mittal
 
PPT
Class and object in C++
rprajat007
 
PPTX
Loops c++
Shivani Singh
 
PPT
Function overloading(c++)
Ritika Sharma
 
PPTX
User defined functions
Rokonuzzaman Rony
 
PPT
Modular programming
Mohanlal Sukhadia University (MLSU)
 
PPTX
Object Oriented Programming Using C++
Muhammad Waqas
 
PPTX
Strings in c++
Neeru Mittal
 
PPT
RECURSION IN C
v_jk
 
PPTX
Recursive Function
Harsh Pathak
 
PPTX
Pointers in c++
Vineeta Garg
 
PPTX
Function in C program
Nurul Zakiah Zamri Tan
 
PPTX
Control statements in c
Sathish Narayanan
 
PPT
Input and output in C++
Nilesh Dalvi
 
PPTX
Union in C programming
Kamal Acharya
 
PDF
Object oriented programming c++
Ankur Pandey
 
PPTX
Java Data Types
Spotle.ai
 
PPTX
Pointers in c++
sai tarlekar
 
PPTX
Operators in Python
Anusuya123
 
classes and objects in C++
HalaiHansaika
 
Operators and expressions in C++
Neeru Mittal
 
Class and object in C++
rprajat007
 
Loops c++
Shivani Singh
 
Function overloading(c++)
Ritika Sharma
 
User defined functions
Rokonuzzaman Rony
 
Object Oriented Programming Using C++
Muhammad Waqas
 
Strings in c++
Neeru Mittal
 
RECURSION IN C
v_jk
 
Recursive Function
Harsh Pathak
 
Pointers in c++
Vineeta Garg
 
Function in C program
Nurul Zakiah Zamri Tan
 
Control statements in c
Sathish Narayanan
 
Input and output in C++
Nilesh Dalvi
 
Union in C programming
Kamal Acharya
 
Object oriented programming c++
Ankur Pandey
 
Java Data Types
Spotle.ai
 
Pointers in c++
sai tarlekar
 
Operators in Python
Anusuya123
 

Viewers also liked (20)

PPT
Operator & Expression in c++
bajiajugal
 
PPT
Operators and Expressions in C++
Praveen M Jigajinni
 
PPTX
Operators and expressions
vishaljot_kaur
 
DOCX
18 dec pointers and scope resolution operator
SAFFI Ud Din Ahmad
 
PPT
Operation and expression in c++
Online
 
PPTX
Lecture 2 C++ | Variable Scope, Operators in c++
Himanshu Kaushik
 
PPT
Types of operators in C
Prabhu Govind
 
PPT
Operators in c language
Amit Singh
 
PDF
Chapter 5 - Operators in C++
Deepak Singh
 
PPTX
Operators
moniammu
 
PPT
CBSE Class XI :- Operators in C++
Pranav Ghildiyal
 
PPT
08 c++ Operator Overloading.ppt
Tareq Hasan
 
PPSX
INTRODUCTION TO C PROGRAMMING
Abhishek Dwivedi
 
PPTX
Operators in C Programming
Jasleen Kaur (Chandigarh University)
 
PPT
Lecture 3
Mohammed Saleh
 
PPTX
Matrices
marcelafernandagarzon
 
DOCX
C – operators and expressions
Chukka Nikhil Chakravarthy
 
PPTX
computer networks
Santosh Jhansi
 
PPTX
Data Types, Variables, and Operators
Marwa Ali Eissa
 
PPTX
03. operators and-expressions
Stoian Kirov
 
Operator & Expression in c++
bajiajugal
 
Operators and Expressions in C++
Praveen M Jigajinni
 
Operators and expressions
vishaljot_kaur
 
18 dec pointers and scope resolution operator
SAFFI Ud Din Ahmad
 
Operation and expression in c++
Online
 
Lecture 2 C++ | Variable Scope, Operators in c++
Himanshu Kaushik
 
Types of operators in C
Prabhu Govind
 
Operators in c language
Amit Singh
 
Chapter 5 - Operators in C++
Deepak Singh
 
Operators
moniammu
 
CBSE Class XI :- Operators in C++
Pranav Ghildiyal
 
08 c++ Operator Overloading.ppt
Tareq Hasan
 
INTRODUCTION TO C PROGRAMMING
Abhishek Dwivedi
 
Operators in C Programming
Jasleen Kaur (Chandigarh University)
 
Lecture 3
Mohammed Saleh
 
C – operators and expressions
Chukka Nikhil Chakravarthy
 
computer networks
Santosh Jhansi
 
Data Types, Variables, and Operators
Marwa Ali Eissa
 
03. operators and-expressions
Stoian Kirov
 
Ad

Similar to Operators in C++ (20)

PPTX
Operators
Krishna Kumar Pankaj
 
PDF
Module 2_PPT_P1 POP Notes module 2 fdfd.pdf
anilcsbs
 
PPTX
What is c
pacatarpit
 
PPTX
object oriented programming presentation
Mahesh_gmail_KNL Na
 
PPT
3d7b7 session4 c++
Mukund Trivedi
 
PPTX
B.sc CSIT 2nd semester C++ Unit2
Tekendra Nath Yogi
 
PPT
Functions in c++
Abdullah Turkistani
 
PPTX
additional.pptx
Yuvraj994432
 
PPTX
BCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptx
RutviBaraiya
 
PPTX
POLITEKNIK MALAYSIA
Aiman Hud
 
PPTX
C Language Part 1
Thapar Institute
 
PPT
C++ chapter 2
SHRIRANG PINJARKAR
 
PPTX
Java chapter 3
Munsif Ullah
 
PPTX
Cs1123 4 variables_constants
TAlha MAlik
 
PPTX
C sharp part 001
Ralph Weber
 
PPT
Basic concept of c++
shashikant pabari
 
PPTX
Few Operator used in c++
sunny khan
 
PPT
C++ Language
Syed Zaid Irshad
 
PDF
Python Unit 3 - Control Flow and Functions
DhivyaSubramaniyam
 
Module 2_PPT_P1 POP Notes module 2 fdfd.pdf
anilcsbs
 
What is c
pacatarpit
 
object oriented programming presentation
Mahesh_gmail_KNL Na
 
3d7b7 session4 c++
Mukund Trivedi
 
B.sc CSIT 2nd semester C++ Unit2
Tekendra Nath Yogi
 
Functions in c++
Abdullah Turkistani
 
additional.pptx
Yuvraj994432
 
BCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptx
RutviBaraiya
 
POLITEKNIK MALAYSIA
Aiman Hud
 
C Language Part 1
Thapar Institute
 
C++ chapter 2
SHRIRANG PINJARKAR
 
Java chapter 3
Munsif Ullah
 
Cs1123 4 variables_constants
TAlha MAlik
 
C sharp part 001
Ralph Weber
 
Basic concept of c++
shashikant pabari
 
Few Operator used in c++
sunny khan
 
C++ Language
Syed Zaid Irshad
 
Python Unit 3 - Control Flow and Functions
DhivyaSubramaniyam
 
Ad

Recently uploaded (20)

PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PDF
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PPSX
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PPTX
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Dimensions of Societal Planning in Commonism
StefanMz
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 

Operators in C++

  • 1. Object-Oriented Programming in C+ + Presented by Sachin Sharma
  • 2. Operators in C++ • The symbols that are used in C++ programs to form an expression are known as operators. C++ has a rich set of operators including all C language’s operators and also some new operators. There are three categories of operators in C++. These are: • Unary Operators • Binary Operators • Ternary Operators
  • 3. Unary Operators • The operators that operate a single operand to form an expression are known as unary operators. The operators like + + (increment) operator, -- (decrement) operator etc. are the part of unary operators.
  • 4. Binary Operators • The operators that operate two or more operands are known as binary operators. The operators like +, -, *, /, % etc. are binary operators. • E.g. a+b, a-b, a*b, a/b etc.
  • 5. Ternary Operators • The operator that operates minimum or maximum three operands is known as ternary operator. There is only one ternary operator available in C++. The operator ?: is the only available ternary operator i.e. used as a substitute of if-else statement. • E.g. a>b ? a:b
  • 6. Types of Operators in C++ • Arithmetic operators • Logical operators • Comparison operators • Assignment operators • Bitwise operators • Scope resolution operator (::) • Line feed operator • Field width operator
  • 7. Arithmetic Operators • The operators that helps the programmer in mathematical calculations are known as arithmetic operators. Arithmetic operators include (+) for addition, (-) for subtraction, (/) for division, (*) for multiplication etc. • E.g. 2+5 = 7
  • 8. Logical Operators • The operators that help the programmer to connect (combine) two or more expressions, are known as logical operators. Logical operators include: 1. && logical AND 2. | | logical OR 3. | logical NOT
  • 9. Comparison Operators • The operators that are used to compare variables to check if they are similar or not. It will return values in true or false. These are also known as relational operators. Comparison operators are: 1. > Greater than 2. < Less than 3. = Equal to
  • 10. Assignment Operators • The operator i.e. used to assign values to identifiers, is known as assignment operator. There is only one assignment operator in C++. The assignment operator (=) is used to assign values to identifiers. • E.g. a = 2 [ assign value 2 to a ]
  • 11. Bitwise Operator • The operators which operate a bit level and allows the programmer to manipulate individual bits. These are basically used for testing or shifting bits. • E.g. x << 3 // Shift three bit position to left
  • 12. Scope Resolution Operator (::) • Like C, C++ is also a block-structured language. A variable declared in a block is said to be local to that block. In C, the global version of a variable cannot be accessed from within the inner block. C++ solves this problem by introducing the new operator :: called the scope resolution operator. This operator allows access to the global version of a variable.
  • 13. Example to use the Scope Resolution Operator • // Program to demonstrate the use of scope resolution operator #include<iostream.h> #include<conio.h> int x = 10; // global x int main() { int x = 20; // x redeclared, local to main { int k = x; int x = 30; // x is declared again in inner block clrscr(); cout << “n We are in inner block n”; cout << “k = “ << k << “n”; cout << “x = “ << x <<“n”; cout << “:: x = “ << :: x <<“n”; } cout << “n We are in outer block n”; cout << “x = “ << x <<“n”; cout << “:: x = “ << :: x <<“n”; return 0; }
  • 14. Output • We are in inner block k = 20 x = 30 :: x = 10 • We are in outer block x = 20 :: x = 10
  • 15. Line Feed Operator & Field Width Operator • These operators are used to format data display. The most commonly used manipulators are endl and setw. • The endl manipulator has the same effect as using the newline character “n”. • The setw manipulator specifies a field width for printing the value of variables.
  • 16. Example to use setw and endl operators • // Program to demonstrate use of endl and setw operators #include<iostream.h> #include<conio.h> #include<iomanip.h> // for setw int main() { int basic = 750, allowance = 75; clrscr(); cout<< “Enter Basic Salary” << setw(10) <<basic<<endl; cout<<“Enter Allowance” << setw(10) <<allowance<<endl; return 0; }
  • 17. Output Enter Basic Salary 750 Enter Allowance 75