c# incrementing logic | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

c# incrementing logic

On the quiz here a = 4; b = 6; b = a++ then console.writeline(++b); was equal to 5. What is the logic here?

29th Jun 2018, 4:01 PM
Ronaldo
3 Answers
0
When evaluated, a++ equates to a before the increment, so is equal to say b = a; // b is 4 a += 1; cons.write(++b) // This increments before getting the value, so 4+1=5, which is the output.
29th Jun 2018, 4:09 PM
Bebida Roja
Bebida Roja - avatar
0
Check about the prefix (++n) and postfix (n++) incrementation. a = 4; b = 6; b = ++a; // b = a, a = a + 1 (b = 4, a = 5) Console.WriteLine(++b) ; // b = b + 1 = 5
29th Jun 2018, 5:05 PM
Boris Batinkov
Boris Batinkov - avatar
0
thanks guys
29th Jun 2018, 6:25 PM
Ronaldo