What is the output of this code? int a = 4; int b = 6; b = a++; Console.WriteLine(++b); | Sololearn: Learn to code for FREE!

+1

What is the output of this code? int a = 4; int b = 6; b = a++; Console.WriteLine(++b);

c#

9/24/2016 9:10:32 AM

Elvin Namazov

10 Answers

New Answer

+6

int a = 4; int b = 6; b = a++; //b=4 and a=5 Console.WriteLine(++b); //b=5

+5

nt a = 4; int b = 6; b = a++; //b=4 and a=5 Console.WriteLine(++b); //b=5 Answer 5

+3

+2

+1

+1

+1

0

Okay but why is the result 4 for b and stops at 5

0

I have the same question, We want to learn here but how i can learn when I don't know why the result 5 is? It is not eneugh to have this questions in SoloLearn we need an Explanation why the Result is 5 and not something else!

0

b is overwrited by (!not incremented) a, and incremented only once in output line. So a and b is 5.