what will be the value of b?? int a = 2; int b = a++ + a++;
By in onSep 18 2013
• 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
• 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
• Really sorry.... It happened by my poor internet connection....

• 1
• a= 4 and b = 5

• 1
• a= 4 and b = 5

• 1
• a= 4 and b = 5

• 1
• a= 4 and b = 5

• 1
• a= 4 and b = 5

• 1
• a= 4 and b = 5

• 1
• a= 4 and b = 5

• 1
• a= 4 and b = 5

• 1
• a= 4 and b = 5

• 1
• a= 4 and b = 5

• 1
• a= 4 and b = 5

• 1
• a= 4 and b = 5

• 1
• a= 4 and b = 5

• 1
• a= 4 and b = 5

• 1
• value of a= 4 and b = 5

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

• 1
• 5

• 1
• b=5

• 1
• 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
• 4

• 1
• 4

• 1
• 5

• 1
• 5

• 1
• 5

• 1
• 5

• 1
• 5

• 1
• 5

• 1
• 5

• 1
• 5

• 1
• 6

• 1
• 5

• 1
• 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
• 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
• 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
• int a=3; int b =4; a=a&2;a=a|b

• 0
• 6

• 0