SlideShare a Scribd company logo
2
Most read
12
Most read
18
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

PPTX
C++ Overview PPT
PPTX
What is an algorithm?
PDF
Introduction to algorithms
PPT
History of c++
PPTX
Quick sort-Data Structure
PPTX
Networking devices
PPTX
Edge Computing.pptx
PPTX
Disaster Mangement For Class IX, CBSE Based
C++ Overview PPT
What is an algorithm?
Introduction to algorithms
History of c++
Quick sort-Data Structure
Networking devices
Edge Computing.pptx
Disaster Mangement For Class IX, CBSE Based

What's hot (20)

PPTX
PPTX
Data types in c++
PPTX
Operators and expressions in C++
PPTX
class and objects
PPTX
07. Virtual Functions
PPTX
classes and objects in C++
PDF
Operator overloading C++
PPTX
Operators in java
PPT
Function overloading(c++)
PPTX
Tokens in C++
PDF
Introduction to c++ ppt
PPTX
Inheritance in c++
PDF
PPTX
Data types
PPTX
Function in C program
PPS
Wrapper class
PPTX
Pointer in c
PPTX
Functions in c language
PPT
08 c++ Operator Overloading.ppt
PPTX
Operator.ppt
Data types in c++
Operators and expressions in C++
class and objects
07. Virtual Functions
classes and objects in C++
Operator overloading C++
Operators in java
Function overloading(c++)
Tokens in C++
Introduction to c++ ppt
Inheritance in c++
Data types
Function in C program
Wrapper class
Pointer in c
Functions in c language
08 c++ Operator Overloading.ppt
Operator.ppt
Ad

Viewers also liked (20)

PPT
Operator & Expression in c++
PPTX
Operator in c programming
PPT
Operators and Expressions in C++
PPTX
Operators and expressions
DOCX
18 dec pointers and scope resolution operator
PPT
Operation and expression in c++
PPTX
Lecture 2 C++ | Variable Scope, Operators in c++
PPT
Types of operators in C
PPT
Operators in c language
PDF
Chapter 5 - Operators in C++
PPTX
Operators
PPT
CBSE Class XI :- Operators in C++
PPSX
INTRODUCTION TO C PROGRAMMING
PPTX
Operators in C Programming
PPT
Lecture 3
PPTX
DOCX
C – operators and expressions
PPTX
computer networks
PPTX
Data Types, Variables, and Operators
PPTX
03. operators and-expressions
Operator & Expression in c++
Operator in c programming
Operators and Expressions in C++
Operators and expressions
18 dec pointers and scope resolution operator
Operation and expression in c++
Lecture 2 C++ | Variable Scope, Operators in c++
Types of operators in C
Operators in c language
Chapter 5 - Operators in C++
Operators
CBSE Class XI :- Operators in C++
INTRODUCTION TO C PROGRAMMING
Operators in C Programming
Lecture 3
C – operators and expressions
computer networks
Data Types, Variables, and Operators
03. operators and-expressions
Ad

Similar to Operators in C++ (20)

PPTX
PPT
Beginning with C++.ppt thus us beginnunv w
PDF
Module 2_PPT_P1 POP Notes module 2 fdfd.pdf
PPTX
What is c
PPTX
object oriented programming presentation
PPT
3d7b7 session4 c++
PPTX
B.sc CSIT 2nd semester C++ Unit2
PPT
Functions in c++
PPTX
additional.pptx
PPTX
BCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptx
PPTX
POLITEKNIK MALAYSIA
PPTX
C Language Part 1
PPT
C++ chapter 2
PPTX
Java chapter 3
PPTX
Cs1123 4 variables_constants
PPTX
C sharp part 001
PPT
Basic concept of c++
PPTX
Operators in c-1.pptxOperators in c-1.pptx
PPTX
Few Operator used in c++
Beginning with C++.ppt thus us beginnunv w
Module 2_PPT_P1 POP Notes module 2 fdfd.pdf
What is c
object oriented programming presentation
3d7b7 session4 c++
B.sc CSIT 2nd semester C++ Unit2
Functions in c++
additional.pptx
BCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptx
POLITEKNIK MALAYSIA
C Language Part 1
C++ chapter 2
Java chapter 3
Cs1123 4 variables_constants
C sharp part 001
Basic concept of c++
Operators in c-1.pptxOperators in c-1.pptx
Few Operator used in c++

Recently uploaded (20)

PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Classroom Observation Tools for Teachers
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
Insiders guide to clinical Medicine.pdf
PDF
Complications of Minimal Access Surgery at WLH
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Cell Types and Its function , kingdom of life
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Pre independence Education in Inndia.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Pharma ospi slides which help in ospi learning
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Business Ethics Teaching Materials for college
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
01-Introduction-to-Information-Management.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Classroom Observation Tools for Teachers
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Insiders guide to clinical Medicine.pdf
Complications of Minimal Access Surgery at WLH
Supply Chain Operations Speaking Notes -ICLT Program
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Cell Types and Its function , kingdom of life
Anesthesia in Laparoscopic Surgery in India
Pre independence Education in Inndia.pdf
PPH.pptx obstetrics and gynecology in nursing
VCE English Exam - Section C Student Revision Booklet
Microbial diseases, their pathogenesis and prophylaxis
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Pharma ospi slides which help in ospi learning
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Business Ethics Teaching Materials for college
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
01-Introduction-to-Information-Management.pdf

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