0
Why ? This output is 0:1:3
static void Main(string[] args) { Person p = new Person(); } class Person{ private static int a = b++; private static int b = ++c; private static int c = 3; public Person(){ Console.WriteLine(a + ":" + b + ":" + c); } } } } https://code.sololearn.com/cH6ffO6l6FGW/?ref=app
2 Answers
+ 3
Lekhraj Singh
First time b is 0 so a is 0
Now after b++, b will be 1
b = ++c, here c is 0 but after ++c, c is 1 so b will be 1
and c = 3
So
a = 0
b = 1
c = 3
Note: ++c means pre increment, first increment by 1 then assign
b++ means post increment, first assign then increment by 1
+ 2
Lekhraj Singh
Here what you have done
a = b++;
// b is unassigned so by default it will take 0 as you have used post increment so first the value 0 is assingned then the value of b goes to 1
// a = 0;
Then
b = ++c;
// here you used pre increment so first the unassigned value of c goes to 1 then assings the value 1 to b
// b = 1;
c = 3;
// now you assigned the value 3 to variable c
// c = 3;
So the output is 0:1:3



