+ 5
What's the meaning and how to use x += 5; ?
I have been seeing this on challanges but still not sure what it actually means... Can someone explain. Thank you 😊
20 Answers
+ 5
x+=5 means x=x+5.
Learn more about it here👇
https://codeforwin.org/2017/08/assignment-shorthand-assignment-operator-c.html
+ 13
Jarred Lazarus
You are welcome,👍
I hope it's clear now.😉
+ 12
Jarred Lazarus
Suppose you had an int variable, sum,
and you wanted to add 10 to it.
How would you do this?
Here's one solution : sum = sum + 10;
This kind of operation is very common (where 10 is replaced by whatever value you want).
//OR
You can use the compound addition assignment operator, which looks like:
+= (plus sign, followed by equal sign).
sum += 10; // Add 10 to sum
Suppose, instead of adding a value to sum, you wanted to double it? That is, you wanted to multiply it by 2?
One way to do this is :
sum = sum * 2; // Multiply sum by 2
//OR
sum *= 2; // Multiply sum by 2
Read the comments in the lessons as you can find a great examples and explanations. 👍
• https://www.sololearn.com/learn/JavaScript/1131/
+ 3
x+=5 is x=x+5
x++ is x=x+1
+ 2
thx for the tip Arsenic . It really helped a lot and I appreciate it much !😊
+ 2
Thank you for replying ~ swim ~ . I gotta be honest some part of it i finish to quick so I didn't really manage to look towarda full detail while finishing it all. I will revise every part of it during my free time. Thanks again ! 😊
+ 2
thanks for the information Danijel Ivanović . 😊
+ 2
It's simple.
X=X+5.
+ 2
thank you @all for replying
+ 2
Maybe this form was first introduced in the C language.
+ 2
Sonic Oh. I directly start SoloLearn with javascript xD
+ 2
•Simple to understand =>
var x ;
x+=5;//x is undefined and x is initializing to 5
•Easy to learn =>
x+=5;//x=x+5;
x=5;//x=0+5;
•In-practical =>
x=undefined;//x is undefined
x=x+5;//x is initializing and adding to 5
Where x = 5; //x is initialize to 5;
+ 2
x+=5 is logically same as
x=x+5
{
if x=2
then
x+=5 equals to 7
}
but it's better practice to write it this way.
i hope you got it.
+ 1
Example:
int x=5;
x+=5 <-------> x=x+5
x=5+5
=10
Both are same
+ 1
x+=5 simply means x = x + 5
Same case applies to all the other mathematical operations.
i.e
x-=5 means x = x - 5
x/=5 means x = x / 5
x*5 means x = x * 5
+ 1
x += 5;
same as
x = x+5;
+ 1
Hi
x+=5
Means : x= x+5
For example:
x=3
x+=5 means x=3+5
Then x=8
Hope help you!
+ 1
X=x+5
+ 1
x=0; x=x+5; result 5