🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 35 (from laksa033)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ℹ️ Skipped - page is already crawled

📄
INDEXABLE
CRAWLED
3 days ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0.1 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://www.programiz.com/cpp-programming/operators
Last Crawled2026-04-15 11:45:45 (3 days ago)
First Indexed2020-03-23 12:22:21 (6 years ago)
HTTP Status Code200
Meta TitleC++ Operators
Meta DescriptionIn this tutorial, we will learn about the different types of operators in C++ with the help of examples. In programming, an operator is a symbol that operates on a value or a variable.
Meta Canonicalnull
Boilerpipe Text
Operators are symbols that perform operations on variables and values. For example, + is an operator used for addition, while - is an operator used for subtraction. Operators in C++ can be classified into 6 types: Arithmetic Operators Assignment Operators Relational Operators Logical Operators Bitwise Operators Other Operators 1. C++ Arithmetic Operators Arithmetic operators are used to perform arithmetic operations on variables and data. For example, a + b; Here, the + operator is used to add two variables a and b . Similarly there are various other arithmetic operators in C++. Operator Operation + Addition - Subtraction * Multiplication / Division % Modulo Operation (Remainder after division) Example 1: Arithmetic Operators #include <iostream> using namespace std; int main() { int a, b; a = 7; b = 2; // printing the sum of a and b cout << "a + b = " << (a + b) << endl; // printing the difference of a and b cout << "a - b = " << (a - b) << endl; // printing the product of a and b cout << "a * b = " << (a * b) << endl; // printing the division of a by b cout << "a / b = " << (a / b) << endl; // printing the modulo of a by b cout << "a % b = " << (a % b) << endl; return 0; } Output a + b = 9 a - b = 5 a * b = 14 a / b = 3 a % b = 1 Here, the operators + , - and * compute addition, subtraction, and multiplication respectively as we might have expected. / Division Operator Note the operation (a / b) in our program. The / operator is the division operator. As we can see from the above example, if an integer is divided by another integer, we will get the quotient. However, if either divisor or dividend is a floating-point number, we will get the result in decimals. In C++, 7/2 is 3 7.0 / 2 is 3.5 7 / 2.0 is 3.5 7.0 / 2.0 is 3.5 % Modulo Operator The modulo operator % computes the remainder. When a = 9 is divided by b = 4 , the remainder is 1 . Note: The % operator can only be used with integers. Increment and Decrement Operators C++ also provides increment and decrement operators: ++ and -- respectively. ++ increases the value of the operand by 1 -- decreases it by 1 For example, int num = 5; // increment operator ++num; // 6 Here, the code ++num; increases the value of num by 1 . Example 2: Increment and Decrement Operators // Working of increment and decrement operators #include <iostream> using namespace std; int main() { int a = 10, b = 100, result_a, result_b; // incrementing a by 1 and storing the result in result_a result_a = ++a; cout << "result_a = " << result_a << endl; // decrementing b by 1 and storing the result in result_b result_b = --b; cout << "result_b = " << result_b << endl; return 0; } Output result_a = 11 result_b = 99 In the above program, we have used the ++ and -- operators as prefixes (++a and --b) . However, we can also use these operators as postfix (a++ and b--) . To learn more, visit increment and decrement operators . 2. C++ Assignment Operators In C++, assignment operators are used to assign values to variables. For example, // assign 5 to a a = 5; Here, we have assigned a value of 5 to the variable a . Operator Example Equivalent to = a = b; a = b; += a += b; a = a + b; -= a -= b; a = a - b; *= a *= b; a = a * b; /= a /= b; a = a / b; %= a %= b; a = a % b; Example 3: Assignment Operators #include <iostream> using namespace std; int main() { int a, b; // 2 is assigned to a a = 2; // 7 is assigned to b b = 7; cout << "a = " << a << endl; cout << "b = " << b << endl; cout << "\nAfter a += b;" << endl; // assigning the sum of a and b to a a += b; // a = a +b cout << "a = " << a << endl; return 0; } Output a = 2 b = 7 After a += b; a = 9 3. C++ Relational Operators A relational operator is used to check the relationship between two operands. For example, // checks if a is greater than b a > b; Here, > is a relational operator. It checks if a is greater than b or not. If the relation is true , it returns 1 whereas if the relation is false , it returns 0 . Operator Meaning Example == Is Equal To 3 == 5 gives us false != Not Equal To 3 != 5 gives us true > Greater Than 3 > 5 gives us false < Less Than 3 < 5 gives us true >= Greater Than or Equal To 3 >= 5 give us false <= Less Than or Equal To 3 <= 5 gives us true Example 4: Relational Operators #include <iostream> using namespace std; int main() { int a, b; a = 3; b = 5; bool result; result = (a == b); // false cout << "3 == 5 is " << result << endl; result = (a != b); // true cout << "3 != 5 is " << result << endl; result = a > b; // false cout << "3 > 5 is " << result << endl; result = a < b; // true cout << "3 < 5 is " << result << endl; result = a >= b; // false cout << "3 >= 5 is " << result << endl; result = a <= b; // true cout << "3 <= 5 is " << result << endl; return 0; } Output 3 == 5 is 0 3 != 5 is 1 3 > 5 is 0 3 < 5 is 1 3 >= 5 is 0 3 <= 5 is 1 Note : Relational operators are used in decision-making and loops. 4. C++ Logical Operators Logical operators are used to check whether an expression is true or false . If the expression is true , it returns 1 whereas if the expression is false , it returns 0 . Operator Example Meaning && expression1 && expression2 Logical AND. True only if all the operands are true. || expression1 || expression2 Logical OR. True if at least one of the operands is true. ! ! expression Logical NOT. True only if the operand is false. In C++, logical operators are commonly used in decision making. To further understand the logical operators, let's see the following examples, Suppose, a = 5 b = 8 Then, (a > 3) && (b > 5) evaluates to true (a > 3) && (b < 5) evaluates to false (a > 3) || (b > 5) evaluates to true (a > 3) || (b < 5) evaluates to true (a < 3) || (b < 5) evaluates to false !(a < 3) evaluates to true !(a > 3) evaluates to false Example 5: Logical Operators #include <iostream> using namespace std; int main() { bool result; result = (3 != 5) && (3 < 5); // true cout << "(3 != 5) && (3 < 5) is " << result << endl; result = (3 == 5) && (3 < 5); // false cout << "(3 == 5) && (3 < 5) is " << result << endl; result = (3 == 5) && (3 > 5); // false cout << "(3 == 5) && (3 > 5) is " << result << endl; result = (3 != 5) || (3 < 5); // true cout << "(3 != 5) || (3 < 5) is " << result << endl; result = (3 != 5) || (3 > 5); // true cout << "(3 != 5) || (3 > 5) is " << result << endl; result = (3 == 5) || (3 > 5); // false cout << "(3 == 5) || (3 > 5) is " << result << endl; result = !(5 == 2); // true cout << "!(5 == 2) is " << result << endl; result = !(5 == 5); // false cout << "!(5 == 5) is " << result << endl; return 0; } Output (3 != 5) && (3 < 5) is 1 (3 == 5) && (3 < 5) is 0 (3 == 5) && (3 > 5) is 0 (3 != 5) || (3 < 5) is 1 (3 != 5) || (3 > 5) is 1 (3 == 5) || (3 > 5) is 0 !(5 == 2) is 1 !(5 == 5) is 0 Explanation of logical operator program (3 != 5) && (3 < 5) evaluates to 1 because both operands (3 != 5) and (3 < 5) are 1 (true). (3 == 5) && (3 < 5) evaluates to 0 because the operand (3 == 5) is 0 (false). (3 == 5) && (3 > 5) evaluates to 0 because both operands (3 == 5) and (3 > 5) are 0 (false). (3 != 5) || (3 < 5) evaluates to 1 because both operands (3 != 5) and (3 < 5) are 1 (true). (3 != 5) || (3 > 5) evaluates to 1 because the operand (3 != 5) is 1 (true). (3 == 5) || (3 > 5) evaluates to 0 because both operands (3 == 5) and (3 > 5) are 0 (false). !(5 == 2) evaluates to 1 because the operand (5 == 2) is 0 (false). !(5 == 5) evaluates to 0 because the operand (5 == 5) is 1 (true). 5. C++ Bitwise Operators In C++, bitwise operators are used to perform operations on individual bits. They can only be used alongside char and int data types. Operator Description & Binary AND | Binary OR ^ Binary XOR ~ Binary One's Complement << Binary Shift Left >> Binary Shift Right To learn more, visit C++ bitwise operators . 6. Other C++ Operators Here's a list of some other common operators available in C++. We will learn about them in later tutorials. Operator Description Example sizeof returns the size of data type sizeof(int); // 4 ?: returns value based on the condition string result = (5 > 0) ? "even" : "odd"; // "even" & represents memory address of the operand &num; // address of num . accesses members of struct variables or class objects s1.marks = 92; -> used with pointers to access the class or struct variables ptr->marks = 92; << prints the output value cout << 5; >> gets the input value cin >> num; Also Read: C++ Operators Precedence and Associativity
Markdown
![](https://www.facebook.com/tr?id=123000288571689&ev=PageView&noscript=1) [Stop copy pasting code you don't actually understand Build the coding confidence you need to become a developer companies will fight for Stop copy pasting code you don't actually understand Ends in Start FREE Trial Start FREE Trial Start FREE Trial Start FREE Trial](https://programiz.pro/?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=programiz&utm_content=default_banner&utm_term=sticky_banner_launch "Start FREE Trial") [Stop copy pasting code you don't actually understand Build the coding confidence you need to become a developer companies will fight for Stop copy pasting code you don't actually understand Ends in Start FREE Trial Start FREE Trial Start FREE Trial Start FREE Trial](https://programiz.pro/?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=programiz&utm_content=default_banner&utm_term=sticky_banner_launch "Start FREE Trial") [![Programiz](https://cdn.programiz.com/sites/tutorial2program/files/sp_logo.svg) ![Programiz](https://cdn.programiz.com/sites/tutorial2program/files/pc_logo.svg)](https://www.programiz.com/ "Programiz") [Tutorials](https://www.programiz.com/cpp-programming/operators "Programming Tutorials") [Examples]("Programming Examples") [![Programiz Pro Logo](https://www.programiz.com/sites/all/themes/programiz/assets/programiz-pro-mini-logo.svg) Courses](https://www.programiz.com/cpp-programming/operators "Learn to Code Interactively") [Try Programiz PRO](https://programiz.pro/learn/master-cpp?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_floating_button "Try Programiz PRO") Course Index Tutorials Courses [Python]("Python") [JavaScript]("JavaScript") [TypeScript]("TypeScript") [SQL]("SQL") [HTML]("HTML") [CSS]("CSS") [C]("C") [C++]("C++") [Java]("Java") [R]("R") [Ruby]("Ruby") [RUST]("RUST") [Golang]("Golang") [Kotlin]("Kotlin") [Swift]("Swift") [C\#]("C#") [DSA]("DSA") Become a certified C++ programmer. [ENROLL](https://programiz.pro/learn/master-cpp?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner) #### Popular Tutorials [C++ if...else Statement](https://www.programiz.com/cpp-programming/if-else?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "C++ if...else Statement") [C++ for Loop](https://www.programiz.com/cpp-programming/for-loop?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "C++ for Loop") [Arrays in C++](https://www.programiz.com/cpp-programming/arrays?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "Arrays in C++") [Strings in C++](https://www.programiz.com/cpp-programming/strings?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "Strings in C++") [C++ Class & Objects](https://www.programiz.com/cpp-programming/object-class?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "C++ Class & Objects") [Start Learning C++](https://www.programiz.com/cpp-programming?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "C++ Tutorials") #### Popular Examples [Create a simple calculator](https://www.programiz.com/cpp-programming/examples/calculator-switch-case?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "Create a simple calculator") [Check prime number](https://www.programiz.com/cpp-programming/examples/prime-number?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "Check prime number") [Print the Fibonacci sequence](https://www.programiz.com/cpp-programming/examples/fibonacci-series?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "Print the Fibonacci sequence") [Check if a number is palindrome or not](https://www.programiz.com/cpp-programming/examples/palindrome-number?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "Check if a number is palindrome or not") [Program to multiply matrix](https://www.programiz.com/cpp-programming/examples/matrix-multiplication?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "Program to multiply matrix") [Explore C++ Examples](https://www.programiz.com/cpp-programming/examples?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "C++ Examples") #### Reference Materials [iostream](https://www.programiz.com/cpp-programming/library-function/iostream?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "iostream") [cmath](https://www.programiz.com/cpp-programming/library-function/cmath?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "cmath") [cstring](https://www.programiz.com/cpp-programming/library-function/cstring?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "cstring") [ctime](https://www.programiz.com/cpp-programming/library-function/ctime?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "ctime") [View all](https://www.programiz.com/cpp-programming/library-function?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "C++ References") ![Programiz Pro Logo](https://www.programiz.com/sites/all/themes/programiz/assets/pro-images/programiz-pro-logo.svg) Created with over a decade of experience. - [Learn]("Learn") - [Practice]("Practice") - [Compete]("Compete") [Learn Python](https://programiz.pro/learn/master-python?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_python&utm_term=nav_programiz-pro_courses "Learn Python") [Learn HTML](https://programiz.pro/course/learn-html?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_html&utm_term=nav_programiz-pro_courses "Learn HTML") [Learn JavaScript](https://programiz.pro/learn/master-javascript?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_javascript&utm_term=nav_programiz-pro_courses "Learn JavaScript") [Learn SQL](https://programiz.pro/course/learn-sql-basics?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_sql&utm_term=nav_programiz-pro_courses "Learn SQL") [Learn DSA](https://programiz.pro/course/dsa-with-python?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_dsa&utm_term=nav_programiz-pro_courses "Learn DSA") [Learn C](https://programiz.pro/learn/master-c-programming?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_c&utm_term=nav_programiz-pro_courses "Learn C") [Learn C++](https://programiz.pro/learn/master-cpp?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_programiz-pro_courses "Learn C++") [Learn Java](https://programiz.pro/learn/master-java?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_java&utm_term=nav_programiz-pro_courses "Learn Java") [View all Courses on ![Programiz Pro Logo](https://www.programiz.com/sites/all/themes/programiz/assets/programiz-pro-mini-logo.svg)](https://programiz.pro/courses?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "View all Courses on PRO") [Python Basics](https://programiz.pro/course/practice-python-basics?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=practice_course_promotion&utm_content=interests_learn_python&utm_term=nav_programiz-pro_practice_courses "Python Basics") [Python Intermediate](https://programiz.pro/course/practice-python-intermediate?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=practice_course_promotion&utm_content=interests_learn_python&utm_term=nav_programiz-pro_practice_courses "Python Intermediate") [C++ Basics](https://programiz.pro/course/practice-cpp-basics?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=practice_course_promotion&utm_content=interests_learn_cpp&utm_term=nav_programiz-pro_practice_courses "C++ Basics") [C++ Intermediate](https://programiz.pro/course/practice-cpp-intermediate?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=practice_course_promotion&utm_content=interests_learn_cpp&utm_term=nav_programiz-pro_practice_courses "C++ Intermediate") [C++ OOP](https://programiz.pro/course/practice-cpp-oop?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=practice_course_promotion&utm_content=interests_learn_cpp&utm_term=nav_programiz-pro_practice_courses "C++ OOP") [C Programming](https://programiz.pro/course/practice-c-programming?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=practice_course_promotion&utm_content=interests_learn_c&utm_term=nav_programiz-pro_practice_courses "C Programming") [Java Basics](https://programiz.pro/course/practice-java-basics?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=practice_course_promotion&utm_content=interests_learn_java&utm_term=nav_programiz-pro_practice_courses "Java Basics") [Java Intermediate](https://programiz.pro/course/practice-java-intermediate?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=practice_course_promotion&utm_content=interests_learn_java&utm_term=nav_programiz-pro_practice_courses "Java Intermediate") [Java OOP](https://programiz.pro/course/practice-java-oop?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=practice_course_promotion&utm_content=interests_learn_java&utm_term=nav_programiz-pro_practice_courses "Java OOP") [View all Courses on ![Programiz Pro Logo](https://www.programiz.com/sites/all/themes/programiz/assets/programiz-pro-mini-logo.svg)](https://programiz.pro/courses?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "View all Courses on PRO") [Python Challenges](https://programiz.pro/community-challenges/python?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=challenge_promotion&utm_content=interests_learn_python&utm_term=nav_programiz-pro_challenges "Python Challenges") [JavaScript Challenges](https://programiz.pro/community-challenges/javascript?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=challenge_promotion&utm_content=interests_learn_javascript&utm_term=nav_programiz-pro_challenges "JavaScript Challenges") [Java Challenges](https://programiz.pro/community-challenges/java?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=challenge_promotion&utm_content=interests_learn_java&utm_term=nav_programiz-pro_challenges "Java Challenges") [C++ Challenges](https://programiz.pro/community-challenges/cpp?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=challenge_promotion&utm_content=interests_learn_cpp&utm_term=nav_programiz-pro_challenges "C++ Challenges") [C Challenges](https://programiz.pro/community-challenges/c?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=challenge_promotion&utm_content=interests_learn_c&utm_term=nav_programiz-pro_challenges "C Challenges") [View all Challenges on ![Programiz Pro Logo](https://www.programiz.com/sites/all/themes/programiz/assets/programiz-pro-mini-logo.svg)](https://programiz.pro/community-challenges?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "View all Challenges on PRO") [Learn]() [Practice]() [Compete]() #### Certification Courses Created with over a decade of experience and thousands of feedback. [Learn Python](https://programiz.pro/learn/master-python?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=challenge_promotion&utm_content=interests_learn_python&utm_term=nav_programiz-pro_challenges "Learn Python") [Learn HTML](https://programiz.pro/course/learn-html?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=challenge_promotion&utm_content=interests_learn_html&utm_term=nav_programiz-pro_challenges "Learn HTML") [Learn JavaScript](https://programiz.pro/learn/master-javascript?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=challenge_promotion&utm_content=interests_learn_javascript&utm_term=nav_programiz-pro_challenges "Learn JavaScript") [Learn SQL](https://programiz.pro/course/learn-sql-basics?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=challenge_promotion&utm_content=interests_learn_sql&utm_term=nav_programiz-pro_challenges "Learn SQL") [Learn DSA](https://programiz.pro/course/dsa-with-python?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=challenge_promotion&utm_content=interests_learn_dsa&utm_term=nav_programiz-pro_challenges "Learn DSA") [View all Courses on ![Programiz Pro Logo](https://www.programiz.com/sites/all/themes/programiz/assets/programiz-pro-mini-logo.svg)](https://programiz.pro/courses?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "View all Courses on PRO") [Learn C](https://programiz.pro/learn/master-c-programming?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=challenge_promotion&utm_content=interests_learn_c&utm_term=nav_programiz-pro_challenges "Learn C") [Learn C++](https://programiz.pro/learn/master-cpp?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=challenge_promotion&utm_content=interests_learn_cpp&utm_term=nav_programiz-pro_challenges "Learn C++") [Learn Java](https://programiz.pro/learn/master-java?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=challenge_promotion&utm_content=interests_learn_java&utm_term=nav_programiz-pro_challenges "Learn Java") [Python]("Python") [JavaScript]("JavaScript") [TypeScript]("TypeScript") [SQL]("SQL") [HTML]("HTML") [CSS]("CSS") [C]("C") [C++]("C++") [Java]("Java") [More languages]("More languages") ### Become a certified C++ programmer. [Try Programiz PRO\!](https://programiz.pro/learn/master-cpp?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner) #### Popular Tutorials [C++ if...else Statement](https://www.programiz.com/cpp-programming/if-else?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "C++ if...else Statement") [C++ for Loop](https://www.programiz.com/cpp-programming/for-loop?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "C++ for Loop") [Arrays in C++](https://www.programiz.com/cpp-programming/arrays?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "Arrays in C++") [Strings in C++](https://www.programiz.com/cpp-programming/strings?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "Strings in C++") [C++ Class & Objects](https://www.programiz.com/cpp-programming/object-class?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "C++ Class & Objects") [Start Learning C++](https://www.programiz.com/cpp-programming?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "C++ tutorials") [All C++ Tutorials](https://www.programiz.com/cpp-programming?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "All C++ tutorials") #### Reference Materials [iostream](https://www.programiz.com/cpp-programming/library-function/iostream?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "iostream") [cmath](https://www.programiz.com/cpp-programming/library-function/cmath?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "cmath") [cstring](https://www.programiz.com/cpp-programming/library-function/cstring?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "cstring") [ctime](https://www.programiz.com/cpp-programming/library-function/ctime?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "ctime") [View all](https://www.programiz.com/cpp-programming/library-function?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_tutorials_banner "C++ References") [Python]("Python") [JavaScript]("JavaScript") [C]("C") [C++]("C++") [Java]("Java") [R]("R") [Kotlin]("Kotlin") Become a certified C++ programmer. [Try Programiz PRO\!](https://programiz.pro/learn/master-cpp?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_examples_banner) #### Popular Examples [Create a simple calculator](https://www.programiz.com/cpp-programming/examples/calculator-switch-case?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_examples_banner "Create a simple calculator") [Check prime number](https://www.programiz.com/cpp-programming/examples/prime-number?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_examples_banner "Check prime number") [Print the Fibonacci sequence](https://www.programiz.com/cpp-programming/examples/fibonacci-series?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_examples_banner "Print the Fibonacci sequence") [Check if a number is palindrome or not](https://www.programiz.com/cpp-programming/examples/palindrome-number?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_examples_banner "Check if a number is palindrome or not") [Program to multiply matrix](https://www.programiz.com/cpp-programming/examples/matrix-multiplication?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_examples_banner "Program to multiply matrix") [All C++ Examples](https://www.programiz.com/cpp-programming/examples?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_campaign=course_promotion&utm_content=interests_learn_cpp&utm_term=nav_examples_banner "C++ Examples") - ### Introduction to C++ - [Getting Started With C++](https://www.programiz.com/cpp-programming/getting-started "Getting Started With C++") - [Your First C++ Program](https://www.programiz.com/cpp-programming/first-program "Your First C++ Program") - [C++ Comments](https://www.programiz.com/cpp-programming/comments "C++ Comments") - ### C++ Fundamentals - [C++ Keywords and Identifiers](https://www.programiz.com/cpp-programming/keywords-identifiers "C++ Keywords and Identifiers") - [C++ Variables, Literals and Constants](https://www.programiz.com/cpp-programming/variables-literals "C++ Variables, Literals and Constants") - [C++ Data Types](https://www.programiz.com/cpp-programming/data-types "C++ Data Types") - [C++ Type Modifiers](https://www.programiz.com/cpp-programming/type-modifiers "C++ Type Modifiers") - [C++ Constants](https://www.programiz.com/cpp-programming/constants "C++ Constants") - [C++ Basic Input/Output](https://www.programiz.com/cpp-programming/input-output "C++ Basic Input/Output") - [C++ Operators](https://www.programiz.com/cpp-programming/operators "C++ Operators") - ### Flow Control - [C++ Relational and Logical Operators](https://www.programiz.com/cpp-programming/relational-logical-operators "C++ Relational and Logical Operators") - [C++ if, if...else and Nested if...else](https://www.programiz.com/cpp-programming/if-else "C++ if, if...else and Nested if...else") - [C++ for Loop](https://www.programiz.com/cpp-programming/for-loop "C++ for Loop") - [C++ while and do...while Loop](https://www.programiz.com/cpp-programming/do-while-loop "C++ while and do...while Loop") - [C++ break Statement](https://www.programiz.com/cpp-programming/break-statement "C++ break Statement") - [C++ continue Statement](https://www.programiz.com/cpp-programming/continue-statement "C++ continue Statement") - [C++ goto Statement](https://www.programiz.com/cpp-programming/goto "C++ goto Statement") - [C++ switch..case Statement](https://www.programiz.com/cpp-programming/switch-case "C++ switch..case Statement") - [C++ Ternary Operator](https://www.programiz.com/cpp-programming/ternary-operator "C++ Ternary Operator") - ### Functions - [C++ Functions](https://www.programiz.com/cpp-programming/function "C++ Functions") - [C++ Programming Default Arguments](https://www.programiz.com/cpp-programming/default-argument "C++ Programming Default Arguments") - [C++ Function Overloading](https://www.programiz.com/cpp-programming/function-overloading "C++ Function Overloading") - [C++ Inline Functions](https://www.programiz.com/cpp-programming/inline-function "C++ Inline Functions") - [C++ Recursion](https://www.programiz.com/cpp-programming/recursion "C++ Recursion") - ### Arrays and Strings - [C++ Arrays](https://www.programiz.com/cpp-programming/arrays "C++ Arrays") - [C++ Array to Function](https://www.programiz.com/cpp-programming/passing-arrays-function "C++ Array to Function") - [C++ Multidimensional Arrays](https://www.programiz.com/cpp-programming/multidimensional-arrays "C++ Multidimensional Arrays") - [C++ String](https://www.programiz.com/cpp-programming/strings "C++ String") - [C++ String Class](https://www.programiz.com/cpp-programming/string-class "C++ String Class") - ### Pointers and References - [C++ Pointers](https://www.programiz.com/cpp-programming/pointers "C++ Pointers") - [C++ Pointers and Arrays](https://www.programiz.com/cpp-programming/pointers-arrays "C++ Pointers and Arrays") - [C++ References: Using Pointers](https://www.programiz.com/cpp-programming/references "C++ References: Using Pointers") - [C++ Call by Reference: Using pointers](https://www.programiz.com/cpp-programming/pointers-function "C++ Call by Reference: Using pointers") - [C++ Memory Management: new and delete](https://www.programiz.com/cpp-programming/memory-management "C++ Memory Management: new and delete") - ### Structures and Enumerations - [C++ Structures](https://www.programiz.com/cpp-programming/structure "C++ Structures") - [C++ Structure and Function](https://www.programiz.com/cpp-programming/structure-function "C++ Structure and Function") - [C++ Pointers to Structure](https://www.programiz.com/cpp-programming/structure-pointer "C++ Pointers to Structure") - [C++ Enumeration](https://www.programiz.com/cpp-programming/enumeration "C++ Enumeration") - ### Object Oriented Programming - [C++ Classes and Objects](https://www.programiz.com/cpp-programming/object-class "C++ Classes and Objects") - [C++ Constructors](https://www.programiz.com/cpp-programming/constructors "C++ Constructors") - [C++ Constructor Overloading](https://www.programiz.com/cpp-programming/constructor-overloading "C++ Constructor Overloading") - [C++ Destructors](https://www.programiz.com/cpp-programming/destructors "C++ Destructors") - [C++ Access Modifiers](https://www.programiz.com/cpp-programming/access-modifiers "C++ Access Modifiers") - [C++ Encapsulation](https://www.programiz.com/cpp-programming/encapsulation "C++ Encapsulation") - [C++ friend Function and friend Classes](https://www.programiz.com/cpp-programming/friend-function-class "C++ friend Function and friend Classes") - ### Inheritance & Polymorphism - [C++ Inheritance](https://www.programiz.com/cpp-programming/inheritance "C++ Inheritance") - [C++ Public, Protected and Private Inheritance](https://www.programiz.com/cpp-programming/public-protected-private-inheritance "C++ Public, Protected and Private Inheritance") - [C++ Multiple, Multilevel and Hierarchical Inheritance](https://www.programiz.com/cpp-programming/multilevel-multiple-inheritance "C++ Multiple, Multilevel and Hierarchical Inheritance") - [C++ Function Overriding](https://www.programiz.com/cpp-programming/function-overriding "C++ Function Overriding") - [C++ Virtual Functions](https://www.programiz.com/cpp-programming/virtual-functions "C++ Virtual Functions") - [C++ Abstract Class and Pure Virtual Function](https://www.programiz.com/cpp-programming/pure-virtual-funtion "C++ Abstract Class and Pure Virtual Function") - ### STL - Vector, Queue & Stack - [C++ Standard Template Library](https://www.programiz.com/cpp-programming/standard-template-library "C++ Standard Template Library") - [C++ STL Containers](https://www.programiz.com/cpp-programming/stl-containers "C++ STL Containers") - [C++ std::array](https://www.programiz.com/cpp-programming/std-array "C++ std::array") - [C++ Vectors](https://www.programiz.com/cpp-programming/vectors "C++ Vectors") - [C++ List](https://www.programiz.com/cpp-programming/list "C++ List") - [C++ Forward List](https://www.programiz.com/cpp-programming/forward-list "C++ Forward List") - [C++ Queue](https://www.programiz.com/cpp-programming/queue "C++ Queue") - [C++ Deque](https://www.programiz.com/cpp-programming/deque "C++ Deque") - [C++ Priority Queue](https://www.programiz.com/dsa/priority-queue "C++ Priority Queue") - [C++ Stack](https://www.programiz.com/cpp-programming/stack "C++ Stack") - ### STL - Map & Set - [C++ Map](https://www.programiz.com/cpp-programming/map "C++ Map") - [C++ Set](https://www.programiz.com/cpp-programming/set "C++ Set") - [C++ Multimap](https://www.programiz.com/cpp-programming/multimap "C++ Multimap") - [C++ Multiset](https://www.programiz.com/cpp-programming/multiset "C++ Multiset") - [C++ Unordered Map](https://www.programiz.com/cpp-programming/unordered-map "C++ Unordered Map") - [C++ Unordered Set](https://www.programiz.com/cpp-programming/unordered-set "C++ Unordered Set") - [C++ Unordered Multiset](https://www.programiz.com/cpp-programming/unordered-multiset "C++ Unordered Multiset") - [C++ Unordered Multimap](https://www.programiz.com/cpp-programming/unordered-multimap "C++ Unordered Multimap") - ### STL - Iterators & Algorithms - [C++ Iterators](https://www.programiz.com/cpp-programming/iterators "C++ Iterators") - [C++ Algorithm](https://www.programiz.com/cpp-programming/algorithm "C++ Algorithm") - [C++ Functor](https://www.programiz.com/cpp-programming/functors "C++ Functor") - ### Additional Topics - [C++ Exceptions Handling](https://www.programiz.com/cpp-programming/exception-handling "C++ Exceptions Handling (With Examples)") - [C++ File Handling](https://www.programiz.com/cpp-programming/file-handling "C++ File Handling") - [C++ Ranged for Loop](https://www.programiz.com/cpp-programming/ranged-for-loop "C++ Ranged for Loop") - [C++ Nested Loop](https://www.programiz.com/cpp-programming/nested-loops "C++ Nested Loop") - [C++ Function Template](https://www.programiz.com/cpp-programming/function-template "C++ Function Template") - [C++ Class Templates](https://www.programiz.com/cpp-programming/class-templates "C++ Class Templates") - [C++ Type Conversion](https://www.programiz.com/cpp-programming/type-conversion "C++ Type Conversion") - [C++ Type Conversion Operators](https://www.programiz.com/cpp-programming/type-conversion-operators "C++ Type Conversion Operators") - [C++ Operator Overloading](https://www.programiz.com/cpp-programming/operator-overloading "C++ Operator Overloading") - ### Advanced Topics - [C++ 11](https://www.programiz.com/cpp-programming/cpp-11 "C++ 11") - [C++ Lambda](https://www.programiz.com/cpp-programming/lambda-expression "C++ Lambda") - [C++ Namespaces](https://www.programiz.com/cpp-programming/namespaces "C++ Namespaces") - [C++ Preprocessors and Macros](https://www.programiz.com/cpp-programming/preprocessor-macros "C++ Preprocessors and Macros") - [C++ Storage Class](https://www.programiz.com/cpp-programming/storage-class "C++ Storage Class") - [C++ Bitwise Operators](https://www.programiz.com/cpp-programming/bitwise-operators "C++ Bitwise Operators") - [C++ Assert](https://www.programiz.com/cpp-programming/assertions "C++ Assert") - [C++ Buffers](https://www.programiz.com/cpp-programming/buffer "C++ Buffers") - [C++ istream](https://www.programiz.com/cpp-programming/istream "C++ istream") - [C++ ostream](https://www.programiz.com/cpp-programming/ostream "C++ ostream") ### C++ Tutorials - [C++ Relational and Logical Operators](https://www.programiz.com/cpp-programming/relational-logical-operators) - [C++ Operator Precedence and Associativity](https://www.programiz.com/cpp-programming/operators-precedence-associativity) - [C++ Bitwise Operators](https://www.programiz.com/cpp-programming/bitwise-operators) - [Subtract Complex Number Using Operator Overloading](https://www.programiz.com/cpp-programming/operator-overloading/binary-operator-overloading) - [Increment ++ and Decrement -- Operator Overloading in C++ Programming](https://www.programiz.com/cpp-programming/increment-decrement-operator-overloading) - [C++ Ternary Operator](https://www.programiz.com/cpp-programming/ternary-operator) # C++ Operators Operators are symbols that perform operations on variables and values. For example, `+` is an operator used for addition, while `-` is an operator used for subtraction. Operators in C++ can be classified into 6 types: 1. [Arithmetic Operators](https://www.programiz.com/cpp-programming/operators#arithmetic) 2. [Assignment Operators](https://www.programiz.com/cpp-programming/operators#assignment) 3. [Relational Operators](https://www.programiz.com/cpp-programming/operators#relational) 4. [Logical Operators](https://www.programiz.com/cpp-programming/operators#logical) 5. [Bitwise Operators](https://www.programiz.com/cpp-programming/operators#bitwise) 6. [Other Operators](https://www.programiz.com/cpp-programming/operators#other-operators) *** ## 1\. C++ Arithmetic Operators Arithmetic operators are used to perform arithmetic operations on variables and data. For example, ``` a + b; ``` Here, the `+` operator is used to add two variables a and b. Similarly there are various other arithmetic operators in C++. | Operator | Operation | |---|---| | `+` | Addition | | `-` | Subtraction | | `*` | Multiplication | | `/` | Division | | `%` | Modulo Operation (Remainder after division) | *** ### Example 1: Arithmetic Operators ``` #include <iostream> using namespace std; int main() { int a, b; a = 7; b = 2; // printing the sum of a and b cout << "a + b = " << (a + b) << endl; // printing the difference of a and b cout << "a - b = " << (a - b) << endl; // printing the product of a and b cout << "a * b = " << (a * b) << endl; // printing the division of a by b cout << "a / b = " << (a / b) << endl; // printing the modulo of a by b cout << "a % b = " << (a % b) << endl; return 0; } ``` **Output** ``` a + b = 9 a - b = 5 a * b = 14 a / b = 3 a % b = 1 ``` Here, the operators `+`, `-` and `*` compute addition, subtraction, and multiplication respectively as we might have expected. **/ Division Operator** Note the operation `(a / b)` in our program. The `/` operator is the division operator. As we can see from the above example, if an integer is divided by another integer, we will get the quotient. However, if either divisor or dividend is a floating-point number, we will get the result in decimals. ``` In C++, 7/2 is 3 7.0 / 2 is 3.5 7 / 2.0 is 3.5 7.0 / 2.0 is 3.5 ``` **% Modulo Operator** The modulo operator `%` computes the remainder. When `a = 9` is divided by `b = 4`, the remainder is **1**. **Note:** The `%` operator can only be used with integers. *** ### Increment and Decrement Operators C++ also provides increment and decrement operators: `++` and `--` respectively. - `++` increases the value of the operand by **1** - `--` decreases it by **1** For example, ``` int num = 5; // increment operator ++num; // 6 ``` Here, the code `++num;` increases the value of num by **1**. *** ### Example 2: Increment and Decrement Operators ``` // Working of increment and decrement operators #include <iostream> using namespace std; int main() { int a = 10, b = 100, result_a, result_b; // incrementing a by 1 and storing the result in result_a result_a = ++a; cout << "result_a = " << result_a << endl; // decrementing b by 1 and storing the result in result_b result_b = --b; cout << "result_b = " << result_b << endl; return 0; } ``` **Output** ``` result_a = 11 result_b = 99 ``` In the above program, we have used the `++` and `--` operators as **prefixes (++a and --b)**. However, we can also use these operators as **postfix (a++ and b--)**. To learn more, visit [increment and decrement operators](https://www.programiz.com/article/increment-decrement-operator-difference-prefix-postfix). *** ## 2\. C++ Assignment Operators In C++, assignment operators are used to assign values to variables. For example, ``` // assign 5 to a a = 5; ``` Here, we have assigned a value of `5` to the variable a. | Operator | Example | Equivalent to | |---|---|---| | `=` | `a = b;` | `a = b;` | | `+=` | `a += b;` | `a = a + b;` | | `-=` | `a -= b;` | `a = a - b;` | | `*=` | `a *= b;` | `a = a * b;` | | `/=` | `a /= b;` | `a = a / b;` | | `%=` | `a %= b;` | `a = a % b;` | *** ### Example 3: Assignment Operators ``` #include <iostream> using namespace std; int main() { int a, b; // 2 is assigned to a a = 2; // 7 is assigned to b b = 7; cout << "a = " << a << endl; cout << "b = " << b << endl; cout << "\nAfter a += b;" << endl; // assigning the sum of a and b to a a += b; // a = a +b cout << "a = " << a << endl; return 0; } ``` **Output** ``` a = 2 b = 7 After a += b; a = 9 ``` *** ## 3\. C++ Relational Operators A relational operator is used to check the relationship between two operands. For example, ``` // checks if a is greater than b a > b; ``` Here, `>` is a relational operator. It checks if a is greater than b or not. If the relation is **true**, it returns **1** whereas if the relation is **false**, it returns **0**. | Operator | Meaning | Example | |---|---|---| | `==` | Is Equal To | `3 == 5` gives us **false** | | `!=` | Not Equal To | `3 != 5` gives us **true** | | `>` | Greater Than | `3 > 5` gives us **false** | | `<` | Less Than | `3 < 5` gives us **true** | | `>=` | Greater Than or Equal To | `3 >= 5` give us **false** | | `<=` | Less Than or Equal To | `3 <= 5` gives us **true** | *** ### Example 4: Relational Operators ``` #include <iostream> using namespace std; int main() { int a, b; a = 3; b = 5; bool result; result = (a == b); // false cout << "3 == 5 is " << result << endl; result = (a != b); // true cout << "3 != 5 is " << result << endl; result = a > b; // false cout << "3 > 5 is " << result << endl; result = a < b; // true cout << "3 < 5 is " << result << endl; result = a >= b; // false cout << "3 >= 5 is " << result << endl; result = a <= b; // true cout << "3 <= 5 is " << result << endl; return 0; } ``` **Output** ``` 3 == 5 is 0 3 != 5 is 1 3 > 5 is 0 3 < 5 is 1 3 >= 5 is 0 3 <= 5 is 1 ``` **Note**: Relational operators are used in decision-making and loops. *** ## 4\. C++ Logical Operators Logical operators are used to check whether an expression is **true** or **false**. If the expression is **true**, it returns **1** whereas if the expression is **false**, it returns **0**. | Operator | Example | Meaning | |---|---|---| | `&&` | expression1 **&&** expression2 | Logical AND. True only if all the operands are true. | | `||` | expression1 **\|\|** expression2 | Logical OR. True if at least one of the operands is true. | | `!` | **\!**expression | Logical NOT. True only if the operand is false. | In C++, logical operators are commonly used in decision making. To further understand the logical operators, let's see the following examples, ``` Suppose, a = 5 b = 8 Then, (a > 3) && (b > 5) evaluates to true (a > 3) && (b < 5) evaluates to false (a > 3) || (b > 5) evaluates to true (a > 3) || (b < 5) evaluates to true (a < 3) || (b < 5) evaluates to false !(a < 3) evaluates to true !(a > 3) evaluates to false ``` *** ### Example 5: Logical Operators ``` #include <iostream> using namespace std; int main() { bool result; result = (3 != 5) && (3 < 5); // true cout << "(3 != 5) && (3 < 5) is " << result << endl; result = (3 == 5) && (3 < 5); // false cout << "(3 == 5) && (3 < 5) is " << result << endl; result = (3 == 5) && (3 > 5); // false cout << "(3 == 5) && (3 > 5) is " << result << endl; result = (3 != 5) || (3 < 5); // true cout << "(3 != 5) || (3 < 5) is " << result << endl; result = (3 != 5) || (3 > 5); // true cout << "(3 != 5) || (3 > 5) is " << result << endl; result = (3 == 5) || (3 > 5); // false cout << "(3 == 5) || (3 > 5) is " << result << endl; result = !(5 == 2); // true cout << "!(5 == 2) is " << result << endl; result = !(5 == 5); // false cout << "!(5 == 5) is " << result << endl; return 0; } ``` **Output** ``` (3 != 5) && (3 < 5) is 1 (3 == 5) && (3 < 5) is 0 (3 == 5) && (3 > 5) is 0 (3 != 5) || (3 < 5) is 1 (3 != 5) || (3 > 5) is 1 (3 == 5) || (3 > 5) is 0 !(5 == 2) is 1 !(5 == 5) is 0 ``` **Explanation of logical operator program** - `(3 != 5) && (3 < 5)` evaluates to **1** because both operands `(3 != 5)` and `(3 < 5)` are **1** (true). - `(3 == 5) && (3 < 5)` evaluates to **0** because the operand `(3 == 5)` is **0** (false). - `(3 == 5) && (3 > 5)` evaluates to **0** because both operands `(3 == 5)` and `(3 > 5)` are **0** (false). - `(3 != 5) || (3 < 5)` evaluates to **1** because both operands `(3 != 5)` and `(3 < 5)` are **1** (true). - `(3 != 5) || (3 > 5)` evaluates to **1** because the operand `(3 != 5)` is **1** (true). - `(3 == 5) || (3 > 5)` evaluates to **0** because both operands `(3 == 5)` and `(3 > 5)` are **0** (false). - `!(5 == 2)` evaluates to **1** because the operand `(5 == 2)` is **0** (false). - `!(5 == 5)` evaluates to **0** because the operand `(5 == 5)` is **1** (true). *** ## 5\. C++ Bitwise Operators In C++, bitwise operators are used to perform operations on individual bits. They can only be used alongside `char` and `int` data types. | Operator | Description | |---|---| | `&` | Binary AND | | `|` | Binary OR | | `^` | Binary XOR | | `~` | Binary One's Complement | | `<<` | Binary Shift Left | | `>>` | Binary Shift Right | To learn more, visit [C++ bitwise operators](https://www.programiz.com/cpp-programming/bitwise-operators). *** ## 6\. Other C++ Operators Here's a list of some other common operators available in C++. We will learn about them in later tutorials. | Operator | Description | Example | |---|---|---| | `sizeof` | returns the size of data type | `sizeof(int); // 4` | | `?:` | returns value based on the condition | `string result = (5 > 0) ? "even" : "odd"; // "even"` | | `&` | represents memory address of the operand | `&num; // address of num` | | `.` | accesses members of struct variables or class objects | `s1.marks = 92;` | | `->` | used with pointers to access the class or struct variables | `ptr->marks = 92;` | | `<<` | prints the output value | `cout << 5;` | | `>>` | gets the input value | `cin >> num;` | *** **Also Read:** - [C++ Operators Precedence and Associativity](https://www.programiz.com/cpp-programming/operators-precedence-associativity) ### Table of Contents - [C++ Operators](https://www.programiz.com/cpp-programming/operators#introduction) - [Arithmetic Operators](https://www.programiz.com/cpp-programming/operators#arithmetic) - [Increment and Decrement Operators](https://www.programiz.com/cpp-programming/operators#increment-decrement) - [Assignment Operators](https://www.programiz.com/cpp-programming/operators#assignment) - [Relational Operators](https://www.programiz.com/cpp-programming/operators#relational) - [Logical Operators](https://www.programiz.com/cpp-programming/operators#logical) - [Other Operators](https://www.programiz.com/cpp-programming/operators#other-operators) Before we wrap up, let’s put your knowledge of C++ Operators to the test! Can you solve the following challenge? Challenge: Write a function to find the sum of three numbers. - Return the sum of the given three numbers `num1`, `num2` and `num3`. - For example, if `num1 = 2`, `num2 = 3`, and `num3 = 4`, the expected output is **9**. Check Code [Previous Tutorial: C++ Basic Input/Output](https://www.programiz.com/cpp-programming/input-output "C++ Basic Input/Output") [Next Tutorial: C++ Relational and Logical Operators](https://www.programiz.com/cpp-programming/relational-logical-operators "C++ Relational and Logical Operators") Share on: Did you find this article helpful? Your builder path starts here. Builders don't just know how to code, they create solutions that matter. Escape tutorial hell and ship real projects. [Try Programiz PRO](https://programiz.pro/?utm_source=programiz.com&utm_medium=referral&utm_audience=ORGANIC-FREEMIUM&utm_content=interests_learn_coding&utm_term=tutorial_page_footer_banner "Programiz PRO: Premium Learning Platform from Programiz") - Real-World Projects - On-Demand Learning - AI Mentor - Builder Community ### Related Tutorials [C++ Tutorial C++ Relational and Logical Operators](https://www.programiz.com/cpp-programming/relational-logical-operators) [C++ Tutorial C++ Operator Precedence and Associativity](https://www.programiz.com/cpp-programming/operators-precedence-associativity) [C++ Tutorial C++ Bitwise Operators](https://www.programiz.com/cpp-programming/bitwise-operators) [C++ Tutorial C++ Ternary Operator](https://www.programiz.com/cpp-programming/ternary-operator) #### Free Tutorials - [Python 3 Tutorials](https://www.programiz.com/python-programming "Python 3 Tutorials") - [SQL Tutorials](https://www.programiz.com/sql "SQL Tutorials") - [R Tutorials](https://www.programiz.com/r "R Tutorials") - [HTML Tutorials](https://www.programiz.com/html "HTML Tutorials") - [CSS Tutorials](https://www.programiz.com/css "CSS Tutorials") - [JavaScript Tutorials](https://www.programiz.com/javascript "JavaScript Tutorials") - [TypeScript Tutorials](https://www.programiz.com/typescript "TypeScript Tutorials") - [Java Tutorials](https://www.programiz.com/java-programming "Java Tutorials") - [C Tutorials](https://www.programiz.com/c-programming "C Tutorials") - [C++ Tutorials](https://www.programiz.com/cpp-programming "C++ Tutorials") - [DSA Tutorials](https://www.programiz.com/dsa "Data Structures and Algorithms") - [C\# Tutorials](https://www.programiz.com/csharp-programming "C# Tutorials") - [Golang Tutorials](https://www.programiz.com/golang "Golang Tutorials") - [Kotlin Tutorials](https://www.programiz.com/kotlin-programming "Kotlin Tutorials") - [Swift Tutorials](https://www.programiz.com/swift-programming "Swift Tutorials") - [Rust Tutorials](https://www.programiz.com/rust "Rust Tutorials") - [Ruby Tutorials](https://www.programiz.com/ruby "Ruby Tutorials") #### Paid Courses - [Master Python](https://programiz.pro/learn/master-python "Master Python") - [Learn SQL](https://programiz.pro/course/learn-sql-basics "Learn SQL") - [Learn HTML](https://programiz.pro/course/learn-html "Learn HTML") - [Master JavaScript](https://programiz.pro/learn/master-javascript "Master JavaScript") - [Master C](https://programiz.pro/learn/master-c-programming "Master C") - [Master C++](https://programiz.pro/learn/master-cpp "Master C++") - [Master Java](https://programiz.pro/learn/master-java "Master Java") - [Master DSA with Python](https://programiz.pro/learn/master-dsa-with-python "Master DSA with Python") #### Online Compilers - [Python Compiler](https://www.programiz.com/python-programming/online-compiler "Python Compiler") - [R Compiler](https://www.programiz.com/r/online-compiler "R Compiler") - [SQL Editor](https://www.programiz.com/sql/online-compiler "SQL Editor") - [HTML/CSS Editor](https://www.programiz.com/html/online-compiler "HTML/CSS Editor") - [JavaScript Editor](https://www.programiz.com/javascript/online-compiler "JavaScript Editor") - [TypeScript Editor](https://www.programiz.com/typescript/online-compiler "TypeScript Editor") - [Java Compiler](https://www.programiz.com/java-programming/online-compiler "Java Compiler") - [C Compiler](https://www.programiz.com/c-programming/online-compiler "C Compiler") - [C++ Compiler](https://www.programiz.com/cpp-programming/online-compiler "C++ Compiler") - [C\# Compiler](https://www.programiz.com/csharp-programming/online-compiler "C# Compiler") - [Go Compiler](https://www.programiz.com/golang/online-compiler "Go Compiler") - [PHP Compiler](https://www.programiz.com/php/online-compiler "PHP Compiler") - [Swift Compiler](https://www.programiz.com/swift/online-compiler "Swift Compiler") - [Rust Compiler](https://www.programiz.com/rust/online-compiler "Rust Compiler") - [Ruby Compiler](https://www.programiz.com/ruby/online-compiler "Ruby Compiler") #### Mobile Apps - [Learn Python App](https://www.programiz.com/learn-python "Learn Python: Programiz") - [Learn C App](https://www.programiz.com/learn-c "Learn C Programming: Programiz") - [Learn Java App](https://www.programiz.com/learn-java "Learn Java: Programiz") - [Learn C++ App](https://www.programiz.com/learn-cpp "Learn C++: Programiz") #### Company - [Change Ad Consent]() - [Do not sell my data]() - [About](https://www.programiz.com/about-us "About us") - [Contact](https://www.programiz.com/contact "Contact us") - [Blog](https://www.programiz.com/blog "Blog") - [Youtube](https://www.youtube.com/channel/UCREFp3D_n8JfcDonlm7Mpyw "Programiz on Youtube") - [Careers](https://www.programiz.com/careers "Careers") - [Advertising](https://www.programiz.com/advertise "Advertise with us") - [Privacy Policy](https://www.programiz.com/privacy-policy "Privacy Policy") - [Terms & Conditions](https://www.programiz.com/terms-of-use "Terms & Conditions") © Parewa Labs Pvt. Ltd. All rights reserved.
Readable Markdown
Operators are symbols that perform operations on variables and values. For example, `+` is an operator used for addition, while `-` is an operator used for subtraction. Operators in C++ can be classified into 6 types: 1. [Arithmetic Operators](https://www.programiz.com/cpp-programming/operators#arithmetic) 2. [Assignment Operators](https://www.programiz.com/cpp-programming/operators#assignment) 3. [Relational Operators](https://www.programiz.com/cpp-programming/operators#relational) 4. [Logical Operators](https://www.programiz.com/cpp-programming/operators#logical) 5. [Bitwise Operators](https://www.programiz.com/cpp-programming/operators#bitwise) 6. [Other Operators](https://www.programiz.com/cpp-programming/operators#other-operators) *** ## 1\. C++ Arithmetic Operators Arithmetic operators are used to perform arithmetic operations on variables and data. For example, ``` a + b; ``` Here, the `+` operator is used to add two variables a and b. Similarly there are various other arithmetic operators in C++. | Operator | Operation | |---|---| | `+` | Addition | | `-` | Subtraction | | `*` | Multiplication | | `/` | Division | | `%` | Modulo Operation (Remainder after division) | *** ### Example 1: Arithmetic Operators ``` #include <iostream> using namespace std; int main() { int a, b; a = 7; b = 2; // printing the sum of a and b cout << "a + b = " << (a + b) << endl; // printing the difference of a and b cout << "a - b = " << (a - b) << endl; // printing the product of a and b cout << "a * b = " << (a * b) << endl; // printing the division of a by b cout << "a / b = " << (a / b) << endl; // printing the modulo of a by b cout << "a % b = " << (a % b) << endl; return 0; } ``` **Output** ``` a + b = 9 a - b = 5 a * b = 14 a / b = 3 a % b = 1 ``` Here, the operators `+`, `-` and `*` compute addition, subtraction, and multiplication respectively as we might have expected. **/ Division Operator** Note the operation `(a / b)` in our program. The `/` operator is the division operator. As we can see from the above example, if an integer is divided by another integer, we will get the quotient. However, if either divisor or dividend is a floating-point number, we will get the result in decimals. ``` In C++, 7/2 is 3 7.0 / 2 is 3.5 7 / 2.0 is 3.5 7.0 / 2.0 is 3.5 ``` **% Modulo Operator** The modulo operator `%` computes the remainder. When `a = 9` is divided by `b = 4`, the remainder is **1**. **Note:** The `%` operator can only be used with integers. *** ### Increment and Decrement Operators C++ also provides increment and decrement operators: `++` and `--` respectively. - `++` increases the value of the operand by **1** - `--` decreases it by **1** For example, ``` int num = 5; // increment operator ++num; // 6 ``` Here, the code `++num;` increases the value of num by **1**. *** ### Example 2: Increment and Decrement Operators ``` // Working of increment and decrement operators #include <iostream> using namespace std; int main() { int a = 10, b = 100, result_a, result_b; // incrementing a by 1 and storing the result in result_a result_a = ++a; cout << "result_a = " << result_a << endl; // decrementing b by 1 and storing the result in result_b result_b = --b; cout << "result_b = " << result_b << endl; return 0; } ``` **Output** ``` result_a = 11 result_b = 99 ``` In the above program, we have used the `++` and `--` operators as **prefixes (++a and --b)**. However, we can also use these operators as **postfix (a++ and b--)**. To learn more, visit [increment and decrement operators](https://www.programiz.com/article/increment-decrement-operator-difference-prefix-postfix). *** ## 2\. C++ Assignment Operators In C++, assignment operators are used to assign values to variables. For example, ``` // assign 5 to a a = 5; ``` Here, we have assigned a value of `5` to the variable a. | Operator | Example | Equivalent to | |---|---|---| | `=` | `a = b;` | `a = b;` | | `+=` | `a += b;` | `a = a + b;` | | `-=` | `a -= b;` | `a = a - b;` | | `*=` | `a *= b;` | `a = a * b;` | | `/=` | `a /= b;` | `a = a / b;` | | `%=` | `a %= b;` | `a = a % b;` | *** ### Example 3: Assignment Operators ``` #include <iostream> using namespace std; int main() { int a, b; // 2 is assigned to a a = 2; // 7 is assigned to b b = 7; cout << "a = " << a << endl; cout << "b = " << b << endl; cout << "\nAfter a += b;" << endl; // assigning the sum of a and b to a a += b; // a = a +b cout << "a = " << a << endl; return 0; } ``` **Output** ``` a = 2 b = 7 After a += b; a = 9 ``` *** ## 3\. C++ Relational Operators A relational operator is used to check the relationship between two operands. For example, ``` // checks if a is greater than b a > b; ``` Here, `>` is a relational operator. It checks if a is greater than b or not. If the relation is **true**, it returns **1** whereas if the relation is **false**, it returns **0**. | Operator | Meaning | Example | |---|---|---| | `==` | Is Equal To | `3 == 5` gives us **false** | | `!=` | Not Equal To | `3 != 5` gives us **true** | | `>` | Greater Than | `3 > 5` gives us **false** | | `<` | Less Than | `3 < 5` gives us **true** | | `>=` | Greater Than or Equal To | `3 >= 5` give us **false** | | `<=` | Less Than or Equal To | `3 <= 5` gives us **true** | *** ### Example 4: Relational Operators ``` #include <iostream> using namespace std; int main() { int a, b; a = 3; b = 5; bool result; result = (a == b); // false cout << "3 == 5 is " << result << endl; result = (a != b); // true cout << "3 != 5 is " << result << endl; result = a > b; // false cout << "3 > 5 is " << result << endl; result = a < b; // true cout << "3 < 5 is " << result << endl; result = a >= b; // false cout << "3 >= 5 is " << result << endl; result = a <= b; // true cout << "3 <= 5 is " << result << endl; return 0; } ``` **Output** ``` 3 == 5 is 0 3 != 5 is 1 3 > 5 is 0 3 < 5 is 1 3 >= 5 is 0 3 <= 5 is 1 ``` **Note**: Relational operators are used in decision-making and loops. *** ## 4\. C++ Logical Operators Logical operators are used to check whether an expression is **true** or **false**. If the expression is **true**, it returns **1** whereas if the expression is **false**, it returns **0**. | Operator | Example | Meaning | |---|---|---| | `&&` | expression1 **&&** expression2 | Logical AND. True only if all the operands are true. | | `||` | expression1 **\|\|** expression2 | Logical OR. True if at least one of the operands is true. | | `!` | **\!**expression | Logical NOT. True only if the operand is false. | In C++, logical operators are commonly used in decision making. To further understand the logical operators, let's see the following examples, ``` Suppose, a = 5 b = 8 Then, (a > 3) && (b > 5) evaluates to true (a > 3) && (b < 5) evaluates to false (a > 3) || (b > 5) evaluates to true (a > 3) || (b < 5) evaluates to true (a < 3) || (b < 5) evaluates to false !(a < 3) evaluates to true !(a > 3) evaluates to false ``` *** ### Example 5: Logical Operators ``` #include <iostream> using namespace std; int main() { bool result; result = (3 != 5) && (3 < 5); // true cout << "(3 != 5) && (3 < 5) is " << result << endl; result = (3 == 5) && (3 < 5); // false cout << "(3 == 5) && (3 < 5) is " << result << endl; result = (3 == 5) && (3 > 5); // false cout << "(3 == 5) && (3 > 5) is " << result << endl; result = (3 != 5) || (3 < 5); // true cout << "(3 != 5) || (3 < 5) is " << result << endl; result = (3 != 5) || (3 > 5); // true cout << "(3 != 5) || (3 > 5) is " << result << endl; result = (3 == 5) || (3 > 5); // false cout << "(3 == 5) || (3 > 5) is " << result << endl; result = !(5 == 2); // true cout << "!(5 == 2) is " << result << endl; result = !(5 == 5); // false cout << "!(5 == 5) is " << result << endl; return 0; } ``` **Output** ``` (3 != 5) && (3 < 5) is 1 (3 == 5) && (3 < 5) is 0 (3 == 5) && (3 > 5) is 0 (3 != 5) || (3 < 5) is 1 (3 != 5) || (3 > 5) is 1 (3 == 5) || (3 > 5) is 0 !(5 == 2) is 1 !(5 == 5) is 0 ``` **Explanation of logical operator program** - `(3 != 5) && (3 < 5)` evaluates to **1** because both operands `(3 != 5)` and `(3 < 5)` are **1** (true). - `(3 == 5) && (3 < 5)` evaluates to **0** because the operand `(3 == 5)` is **0** (false). - `(3 == 5) && (3 > 5)` evaluates to **0** because both operands `(3 == 5)` and `(3 > 5)` are **0** (false). - `(3 != 5) || (3 < 5)` evaluates to **1** because both operands `(3 != 5)` and `(3 < 5)` are **1** (true). - `(3 != 5) || (3 > 5)` evaluates to **1** because the operand `(3 != 5)` is **1** (true). - `(3 == 5) || (3 > 5)` evaluates to **0** because both operands `(3 == 5)` and `(3 > 5)` are **0** (false). - `!(5 == 2)` evaluates to **1** because the operand `(5 == 2)` is **0** (false). - `!(5 == 5)` evaluates to **0** because the operand `(5 == 5)` is **1** (true). *** ## 5\. C++ Bitwise Operators In C++, bitwise operators are used to perform operations on individual bits. They can only be used alongside `char` and `int` data types. | Operator | Description | |---|---| | `&` | Binary AND | | `|` | Binary OR | | `^` | Binary XOR | | `~` | Binary One's Complement | | `<<` | Binary Shift Left | | `>>` | Binary Shift Right | To learn more, visit [C++ bitwise operators](https://www.programiz.com/cpp-programming/bitwise-operators). *** ## 6\. Other C++ Operators Here's a list of some other common operators available in C++. We will learn about them in later tutorials. | Operator | Description | Example | |---|---|---| | `sizeof` | returns the size of data type | `sizeof(int); // 4` | | `?:` | returns value based on the condition | `string result = (5 > 0) ? "even" : "odd"; // "even"` | | `&` | represents memory address of the operand | `&num; // address of num` | | `.` | accesses members of struct variables or class objects | `s1.marks = 92;` | | `->` | used with pointers to access the class or struct variables | `ptr->marks = 92;` | | `<<` | prints the output value | `cout << 5;` | | `>>` | gets the input value | `cin >> num;` | *** **Also Read:** - [C++ Operators Precedence and Associativity](https://www.programiz.com/cpp-programming/operators-precedence-associativity)
Shard35 (laksa)
Root Hash16786490165506891835
Unparsed URLcom,programiz!www,/cpp-programming/operators s443