0% found this document useful (0 votes)
38 views4 pages

C++ Comparison Ass Operators

The document provides an overview of comparison and assignment operators in C++. It explains how comparison operators are used to compare values and return Boolean results, while assignment operators are used to assign values to variables. A list of various operators with examples is also included.

Uploaded by

Elsa Olivia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views4 pages

C++ Comparison Ass Operators

The document provides an overview of comparison and assignment operators in C++. It explains how comparison operators are used to compare values and return Boolean results, while assignment operators are used to assign values to variables. A list of various operators with examples is also included.

Uploaded by

Elsa Olivia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

 Tutorials  Exercises  Get Certified  Services  Search...

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

C++ Comparison Operators


❮ Previous Next ❯

Comparison Operators
Comparison operators are used to compare two values (or variables). This is
important in programming, because it helps us to find answers and make decisions.

The return value of a comparison is either 1 or 0 , which means true (1) or false
(0). These values are known as Boolean values, and you will learn more about them
in the Booleans and If..Else chapter.

In the following example, we use the greater than operator ( > ) to find out if 5 is
greater than 3:

Example

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

Try it Yourself »

A list of all comparison operators:


Operator
Tutorials  Exercises 
Name
Get Certified  Services 
Example Try it

HTML
 == CSS JAVASCRIPT
Equal toSQL PYTHON JAVA
x == y PHP HOW TO W3.CSS C
Try it »

!= Not equal x != y Try it »

> Greater than x>y Try it »

< Less than x<y Try it »

>= Greater than or equal to x >= y Try it »

<= Less than or equal to x <= y Try it »

You will learn much more about comparison operators and how to use them in a later
chapter.

❮ Previous Log in to track progress Next ❯


 Tutorials  Exercises  Get Certified  Services  Search...

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

C++ Assignment Operators


❮ Previous Next ❯

Assignment Operators
Assignment operators are used to assign values to variables.

In the example below, we use the assignment operator ( = ) to assign the value 10
to a variable called x:

Example

int x = 10;

Try it Yourself »

The addition assignment operator ( += ) adds a value to a variable:

Example

int x = 10;
x += 5;
Try it Yourself »
Tutorials  Exercises  Get Certified  Services 

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
A list of all assignment operators:

Operator Example Same As Try it

= x=5 x=5 Try it »

+= x += 3 x=x+3 Try it »

-= x -= 3 x=x-3 Try it »

*= x *= 3 x=x*3 Try it »

/= x /= 3 x=x/3 Try it »

%= x %= 3 x=x%3 Try it »

&= x &= 3 x=x&3 Try it »

|= x |= 3 x=x|3 Try it »

^= x ^= 3 x=x^3 Try it »

>>= x >>= 3 x = x >> 3 Try it »

<<= x <<= 3 x = x << 3 Try it »

❮ Previous Log in to track progress Next ❯

You might also like