C++ Operators - Learn C++ Programming

In this lesson, We will talk about C++ Operators – Learn C++ Programming. In c++, We have a lot of operators. We are using operators to perform operations with variables and values.

So, the Example below, that we use the addition operator “+” to add together two values.

and the Example is:

#include <iostream>
using namespace std;

int main(){
    int sum = 80 + 20;
    cout << sum;
    return 0;
}

Then the Output:

100

Hey! you can learn although the + operator is often using to add two values together, so, like in the example above, OK. You can also use to add variables and values, or a variable with another variable.

So, look at the Example:

#include <iostream>
using namespace std;

int main(){
    int sum1, midSum, finalSum;
    sum1 = 80 + 20 << endl;
    midSum = sum1 + 100 << endl;
    finalSum = Sum1 + midSum << endl;
    cout << sum1;
    cout << midSum;
    cout << finalSum;
    return 0;
}

Then, look at Output:

100
200
300

So, we design a new category for you For Operators click here for Learn C++ Operators.

So, lets Here the Arithmetic Operators

  • Operator: +
  • Name: Addition
  • Description: So, This Operator is used for adding two values together,
  • Syntax: x + y
  • Example: So, the example is Above the first section.

So, we give you a list in below the show Subtraction operator details Check the below.

  • Operator ( – )
  • Name: Subtraction
  • Description: So, This Operator is used for subtract one value to another value
  • Syntax: x – y
  • Example: So, the example is below the first section.

So look at Example first:

#include <iostream>
using namespace std;

int main(){
    int x = 120;
    int y = 40
    cout << x - y;
    return 0;
}

Then, See here Output:

80

So, another list we provide you in below the show Multiply operator details Checks the below.

  • Operator ( * )
  • Name: Multiplication
  • Description: So, This Operator is used to Multiply two values
  • Syntax: x * y
  • Example: So, the example is below the first section.

So, see here the Example:

#include <iostream>
using namespace std;

int main(){
    int x = 15;
    int y = 7;
    cout << x * y;
    return 0;
}

Then, the output is:

105

4 other C++ Operators Table with Example and Learn C++

So, I know, you have to do so many works, I am teaching you, the other four Operators, in a table and make its example in a big C++ program.

OperatorNameDescriptionSyntaxExample
/DivisionDivide a value with anther valuex / y Below
%Modulus use for reminder of two value divided x % yBelow
++IncrementIncrease the value by 1 value++xBelow
Decrement Decrease the value by 1 value–yBelow
Table for C++ Operators

So, I know, I tell you in the previous paragraph, that I will write a huge C++ Program with reminder Operators.

Then, Here is Example:

#include <iostream>
using namespace std;

int main(){
    int x = 15;
    int y = 7;
    cout << "This value is With Division Operator: " << x / y<< endl;
    cout << "This value is With Modulus Operator: " << x % y<< endl;
    ++x;
    cout << "This value is Increase: " << x << endl;
    --y;
	cout << "This value is Decrease: " << y << endl;
    return 0;
}

So, see at Output:

This value is With Division Operator: 2
This value is With Modulus Operator: 1
This value is Increase: 16
This value is Decrease: 6

Note: Integer Value never returns floating-point number, because, C++ has an anther data type to return floating-point number. But you can read the Variable chapter of C++.

Remember: If you only learn this course and you did not do hard work practices, then it can not help you in the future. So, please do hard work to make your powerful future.

By Usama Arshad

It's me Usama Arshad working as a Lecturer C++. I am a student of BSIT.

Leave a Reply

Your email address will not be published. Required fields are marked *