CP2 Module 3 - Operators in C++
CP2 Module 3 - Operators in C++
COMPUTER PRORAMMING 2 2
What is a C++ Operator?
• are used to perform operations on variables and values
• use the + operator to add together values
COMPUTER PROGRAMMING 2 3
What are the types C++ Operators?
• Arithmetic – perform common mathematical operations
• Assignment – used to assign values to variables.
• Comparison - used to compare two values (true or false).
• Logical – used to determine the logic between variables or
values (and, or, not)
COMPUTER PROGRAMMING 2 4
Arithmetic Operators:
- perform common mathematical operations
COMPUTER PROGRAMMING 2 5
Source: https://www.w3schools.com/cpp/cpp_operators.asp
Arithmetic Operators:
- sample code in C++
COMPUTER PROGRAMMING 2 6
Source: https://www.w3schools.com/cpp/cpp_operators.asp
Assignment Operators:
- used to assign values to variables.
COMPUTER PROGRAMMING 2 7
Source:
https://www.w3schools.com/cpp/cpp_operators_assignment.asp
Assignment Operators:
COMPUTER PROGRAMMING 2 8
Source:
https://www.w3schools.com/cpp/cpp_operators_assignment.asp
Comparison Operators:
- The return value of a comparison is either true (1) or false (0)
COMPUTER PROGRAMMING 2 9
Source: https://www.w3schools.com/cpp/cpp_operators_comparison.asp
Comparison Operators:
COMPUTER PROGRAMMING 2 10
Source: https://www.w3schools.com/cpp/cpp_operators_comparison.asp
Logical Operators:
- used to determine the logic between variables or values:
COMPUTER PROGRAMMING 2 11
Source: https://www.w3schools.com/cpp/cpp_operators_logical.asp
Logical "AND" and "OR" Operators:
COMPUTER PROGRAMMING 2 12
Source: https://www.w3schools.com/cpp/cpp_operators_logical.asp
Logical "NOT" Operators:
COMPUTER PROGRAMMING 2 13
Source: https://www.w3schools.com/cpp/cpp_operators_logical.asp
Logical Operators:
COMPUTER PROGRAMMING 2 14
Source: https://www.w3schools.com/cpp/cpp_operators_logical.asp
References:
• Pomperada, Jake. 2019. Beginner’s Guide to C++ Programming.
Manila: Mindshapers Co., Inc.
• Pepito, Copernicus. 2009. Introduction to C++ 2008 programming.
Manila: National Bookstore.
• https://www.codecademy.com/courses/learn-c-plus-plus
• https://www.w3schools.com/cpp/default.asp
• https://www.tutorialspoint.com/cplusplus/index.htm
COMPUTER PROGRAMMING 2 15
COMPUTER PROGRAMMING 2 16
COMPUTER PRORAMMING 2