What happens if (++aNumber)? Say aNumber = 1 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What happens if (++aNumber)? Say aNumber = 1

14th Sep 2016, 11:58 PM
Kyle
5 Answers
+ 1
int aNumber = 1; Console.WriteLine(++aNumber); //prints 2, and aNumber is now 2
15th Sep 2016, 12:12 AM
Zen
Zen - avatar
+ 1
It pre increments the number before being used, so it gets incremented first and then gets assigned to some other variable. I hope this helps.
15th Sep 2016, 5:47 PM
Dhiraj Bhavsar
0
Thanks bunches
15th Sep 2016, 12:19 AM
Kyle
0
Well... crap. Would it be the same for magic numbers?
15th Sep 2016, 12:24 AM
Kyle
0
in if, apart from 0, everything else is true. so, its 1 or 2 doesn't actually matter.
15th Sep 2016, 8:07 AM
Nagendra Prajwal
Nagendra Prajwal - avatar