what will be the value of b?? int a = 2; int b = a++ + a++;
By in on Sep 18 2013
• Sep, 2013 24

a=2; b=a++ + a++; As we know in an assignment expression assocciativity is right--> left. so here right side a value 2 is taken as the operand and after that a's value 2 increments to 3, and then left side a's value becomes 3. so 3 is taken as another operand and after that 3 is increments to 4. but the addition and assignment performs before a's value becomes 4.

• 2
• Sep, 2013 18

int a = 2; int b = a++ + a++; int c = ++a + a++ + a++; +-----+------+------+----+ |  C  | C++ | Java | C# | +-----+-----+------+------+----+ | a   | 7 | 7 | 7 | 7 | +-----+-----+------+------+----+ | b   | 4 | 4 | 5 | 5 | +-----+-----+------+------+----+ | c   | 15 | 15 | 16 | 16 | +-----+-----+------+------+----+

• 2
• Dec, 2016 1

Really sorry.... It happened by my poor internet connection....

• 1
• Dec, 2016 1

a= 4 and b = 5

• 1
• Dec, 2016 1

a= 4 and b = 5

• 1
• Dec, 2016 1

a= 4 and b = 5

• 1
• Dec, 2016 1

a= 4 and b = 5

• 1
• Dec, 2016 1

a= 4 and b = 5

• 1
• Dec, 2016 1

a= 4 and b = 5

• 1
• Dec, 2016 1

a= 4 and b = 5

• 1
• Dec, 2016 1

a= 4 and b = 5

• 1
• Dec, 2016 1

a= 4 and b = 5

• 1
• Dec, 2016 1

a= 4 and b = 5

• 1
• Dec, 2016 1

a= 4 and b = 5

• 1
• Dec, 2016 1

a= 4 and b = 5

• 1
• Dec, 2016 1

a= 4 and b = 5

• 1
• Dec, 2016 1

a= 4 and b = 5

• 1
• Feb, 2016 5

value of a= 4 and b = 5

• 1
• Jun, 2015 16

Depending on the compiler you use... This is a bad programming style

• 1
• May, 2015 27

5

• 1
• Apr, 2015 29

b=5

• 1
• Apr, 2015 29

int a = 2; int b = a++ + a++; //right to left value of first a++=2 and then a=3 so second a++=3 after that a=4 b=3+2; b=5;

• 1
• Mar, 2015 22

4

• 1
• Sep, 2014 17

4

• 1
• Jul, 2014 17

5

• 1
• May, 2014 24

5

• 1
• Mar, 2014 31

5

• 1
• Mar, 2014 31

5

• 1
• Mar, 2014 31

5

• 1
• Mar, 2014 31

5

• 1
• Mar, 2014 31

5

• 1
• Mar, 2014 31

5

• 1
• Feb, 2014 17

6

• 1
• Jan, 2014 8

5

• 1
• Dec, 2013 18

int a = 2; int b = a++;int c = a++;int d = b + c;Console.WriteLine("b={0}", b);Console.WriteLine("c={0}", c);Console.WriteLine("d={0}", d);Console.ReadLine();

• 1
• Dec, 2013 18

int a = 2; int b = a++;int c = a++;int d = b + c;Console.WriteLine("b={0}", b);Console.WriteLine("c={0}", c);Console.WriteLine("d={0}", d);Console.ReadLine();

• 1
• Sep, 2013 24

a=2; b=a++ + a++; As we know in an assignment expression assocciativity is right--> left. so here right side a value 2 is taken as the operand and after that a's value 2 increments to 3, and then left side a's value becomes 3. so 3 is taken as another operand and after that 3 is increments to 4. but the addition and assignment performs before a's value becomes 4.

• 1
• Apr, 2019 2

int a=3; int b =4; a=a&2;a=a|b

• 0
• Jul, 2018 29

6

• 0