0

Int a=4;int b=6; b=a++; console.writeline(++b):

what is the output for this concept

1st Nov 2016, 7:42 AM
Hari Haran
Hari Haran - avatar
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.
1st Nov 2016, 9:33 AM
Wen Qin
Wen Qin - avatar
+ 1
5
1st Nov 2016, 7:50 AM
Esteban Juarez Rodriguez
Esteban Juarez Rodriguez - avatar
+ 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
1st Nov 2016, 8:22 AM
Esteban Juarez Rodriguez
Esteban Juarez Rodriguez - avatar
0
5 is correct ans
1st Nov 2016, 9:15 AM
Hari Haran
Hari Haran - avatar
- 1
4
1st Nov 2016, 9:01 AM
ali yahyaee
ali yahyaee - avatar