Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 10

COMPUTER

PROGRAMMING
LECTURE #07
C++ OPERATORS

C++ divides the operators into the following groups:


• Arithmetic operators
• Comparison operators
• Assignment operators
• Logical operators
ARITHMETIC OPERATORS
EXAMPLE

#include <iostream>
using namespace std;

int main() {
int x = 5;
int y = 2;
cout << x % y;
return 0;
}
COMPARISON OPERATORS

Comparison operators are used to compare two values.


Note: The return value of a comparison is either true (1) or false (0).
EXAMPLE

int x = 5;
int y = 3;
cout << (x > y); // returns 1 (true) because 5 is greater than 3
ASSIGNMENT OPERATORS

• Assignment operators are used to assign values to variables.


EXAMPLE

#include <iostream>
using namespace std;
int main() {
int x = 10;
x += 5;
cout << x;
return 0;
}
LOGICAL OPERATORS
EXAMPLE

#include <iostream>
using namespace std;
int main() {
int x = 5;
int y = 3;
cout << (x > 3 && x < 10);
// returns true (1) because 5 is greater than 3 AND 5 is less than 10
return 0;
}

You might also like