Adding in C++ | SoloLearn: Learn to code for FREE!

+5

Adding in C++

What's the difference between a = a+1 and a += 1? I noticed when I tried using a+2 in a loop, it responded with a timeout error.

c++

2/14/2019 10:35:08 PM

Daniel Cooper

3 Answers

New Answer

+6

a = a +1 is the same as a += 1 and still the same as a++ however if you use a+2 you bound to get a timeout error since value of "a" is never changed in that expression so use a = a+1, a+=1 or just simply a++ hope this help you

+3

Ok, so that makes sense So I'd have to do a = a+2. which could be shortened with a+=2. Thanks Mind To Machine 💻🕆

+2

anytime Daniel Cooper 😊😎😉