If I go
variable1 =+ variable2
variable1 += variable2
I get the same result for variable1.
So is there any difference?
The ' |= ' symbol is the bitwise OR assignment operator.
In mathematics, the tilde often represents approximation, especially when used in duplicate, and is sometimes called the "equivalency sign." In regular expressions, the tilde is used as an operator in pattern matching, and in C programming, it is used as a bitwise operator representing a unary negation (i.e., "bitwise ...
An operator is a symbol that tells the compiler to perform specific mathematical or logical functions. C language is rich in built-in operators and provides the following types of operators − Arithmetic Operators.
In C/C++, the # sign marks preprocessor directives. If you're not familiar with the preprocessor, it works as part of the compilation process, handling includes, macros, and more.
The difference is that your observation is not correct and variable1 =+ variable2
does not add variable2 to variable1, but rather sets variable1 equal to variable2. The line is really variable1 = +variable2
, or simply variable1 = variable2
.
Consider this code
int a = 10;
int b = 20;
a =+ b;
a += b;
At the end of this process, a
equals 40. It is intialized to 10, b
is initialized to 20, a
is set equal to b
, and then b
gets added to a
.
Yes there is a difference.
int x = 0;
x += 1; --> x = x + 1; (you are adding 1 to x)
x =+ 1; --> x = +1; (you are assigning x a value)
Yes, using a toy example I show them as different.
In the case of variable1 =+ variable2
you're effectively computing
variable1 = 0 + variable2
or simply
variable1 = variable2
In the case of variable1 += variable2
you're effectively computing
variable1 = variable1 + variable2
Perhaps it's best to state that there is no =+ operator in C#. But you can use a unary + to indicate a positive number (always redundant, but included for completeness).
And for completeness of this answer, x += y is the same as x = x + y.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With