
The assignment operator (operator =) assigns the value/result of an expression to a variable. This works from right to left. In addition to the build-in direct assignment operators, C++ supports “move assignment” for class types. This is a special member function that avoids copying by replacing the contents of an existing object with another one.
Subtract
The subtraction arithmetic operator in C++ programming subtracts the value of its left and right operands. It is one of the most basic mathematical operators in C++. The program below asks the user to enter two numbers and performs the subtraction operation on them. The result is displayed on the screen.
In C++, the - operator is used for performing subtraction operations with integer data types. It can also be used for subtraction operations with float data types. It is similar to the XOR operation for boolean values. As with other assignment operators, you can use multiple assignments in a single statement in C++. You can use different types of assignment operators, such as the equality operator, '=". The compiler automatically provides a default copy assignment operator for your class, which does memberwise assignment.
Multiply
Multiplication is a basic arithmetic operation that can be used in many applications. In C++ programming, the assignment operator (=) can be used to multiply values. This is done by assigning the value of the right-hand operand to the left-hand one. The value of the right-hand side will then be multiplied by the value of the left-hand side.
Note that the assignment operators for class types are different than those for non-class types. The copy assignment operator copies the data members of class A, whereas the move assignment operator replaces the contents of an existing object. This code program multiplies two numbers without using the multiplication operator. The result is displayed on the screen. This is done by using a for loop, which adds the value of the first number to the variable product each iteration.
Divide
The '/' operator divides a value on the left side of the operand with a value on the right and assigns the result to the variable on the left. If the value on the left is a variable, this will create a copy of that variable.
If both the division operands are floating point numbers, the compiler will perform floating point division and the fractional part will be kept (7.0 / 4 = 1.75). If both are integers, the division will perform integer division, and the remainder will be dropped.
In this program, we'll use a class to demonstrate the different assignment operator in c++. We'll also show how to handle self-assignment on a class in a non-object-oriented way. This can cause major bugs in your code if you don't handle it properly.
Modulus
A program is a set of instructions to be executed by the computer. These instructions are written in a programming language. The notation used in a program may seem strange to non-programmers. It is part of the syntax of the language. The program below reads two numbers typed by a user at the keyboard and computes their sum and prints it on screen. The program uses several assignment operators.
A derived class has an implicit copy assignment operator that hides the copy assignment operator of its base class. The default version of this operator assigns the lvalues and rvalues of class A in the order in which they appear in its definition. However, you can override the default version of the operator by explicitly declaring a copy assignment operator.
XOR
This assignment operator applies a logical exclusive OR operation to the value of a variable, property or array element. It evaluates the expression on the right before assigning it to the left. If the expression is not numeric or Boolean, it first coerces it to a number. If it is a BigInt, it performs BigInt bitwise XOR. A TypeError is thrown if one of the operands becomes a BigInt and the other remains a number.
A move assignment is equivalent to this op, except that it avoids copying if possible (the left operand may be a class type). The following program demonstrates the usage of these arithmetic operators. It starts with defining two integer variables a and b. Then the program performs XOR operation on these two integer variables and stores the result in a variable.