0
Int a=4;int b=6; b=a++; console.writeline(++b):
what is the output for this concept
5 Answers
+ 8
Actually, this code will get an error since
1. Coding is case sensitive, you need to use Console.WriteLine , not ' console.writeline '
But anyway lets just say that we fixed the error.
The output will be 5
Why? Even though we declared b as 6 before, we did not lock/seal it, meaning that we can easily change it.
First minor problem, b = ++a; Remember your lessons, the ++ is at the left side of the integer, meaning that it will read first before adding it by 1. Hence, by the time a was added by 1, b would have already became a, which is 4.
Now we have a second minor problem, we place in the input of Console.WriteLine as ++b . But if you remember your C# lessons, if we put ++ on the left of the integer, the console will add first, then read. Hence, by the time the console gave it's output, b, which is 4, would have already been added by 1.
+ 1
5
+ 1
You declare a = 4 and b=6. after that You asign the value of a++ to b so b=4 because b=a and a=a+1. finally You print the ++b so it is b=b+1= 6 and that is what u print
0
5 is correct ans
- 1
4