Vivek Sharma
what will be the value of b?? int a = 2; int b = a++ + a++;
By Vivek Sharma in OOP/OOD on Sep 18 2013
  • sudarsan pradhan
    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
  • Vivek Sharma
    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
  • Ramesh S
    Dec, 2016 1

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

    • 1
  • Ramesh S
    Dec, 2016 1

    a= 4 and b = 5

    • 1
  • Ramesh S
    Dec, 2016 1

    a= 4 and b = 5

    • 1
  • Ramesh S
    Dec, 2016 1

    a= 4 and b = 5

    • 1
  • Ramesh S
    Dec, 2016 1

    a= 4 and b = 5

    • 1
  • Ramesh S
    Dec, 2016 1

    a= 4 and b = 5

    • 1
  • Ramesh S
    Dec, 2016 1

    a= 4 and b = 5

    • 1
  • Ramesh S
    Dec, 2016 1

    a= 4 and b = 5

    • 1
  • Ramesh S
    Dec, 2016 1

    a= 4 and b = 5

    • 1
  • Ramesh S
    Dec, 2016 1

    a= 4 and b = 5

    • 1
  • Ramesh S
    Dec, 2016 1

    a= 4 and b = 5

    • 1
  • Ramesh S
    Dec, 2016 1

    a= 4 and b = 5

    • 1
  • Ramesh S
    Dec, 2016 1

    a= 4 and b = 5

    • 1
  • Ramesh S
    Dec, 2016 1

    a= 4 and b = 5

    • 1
  • Ramesh S
    Dec, 2016 1

    a= 4 and b = 5

    • 1
  • Anil Kumar Murmu
    Feb, 2016 5

    value of a= 4 and b = 5

    • 1
  • Nachiappan NK
    Jun, 2015 16

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

    • 1
  • Rahul Prajapat
    May, 2015 27

    5

    • 1
  • Manoj Bhoir
    Apr, 2015 29

    b=5

    • 1
  • Anil
    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
  • Pankaj  Kumar Choudhary
    Mar, 2015 22

    4

    • 1
  • Bhawna Raghuvanshi
    Sep, 2014 17

    4

    • 1
  • Divendra Ojha
    Jul, 2014 17

    5

    • 1
  • Bhabani Prasad
    May, 2014 24

    5

    • 1
  • Mahaveer Yadav
    Mar, 2014 31

    5

    • 1
  • Mahaveer Yadav
    Mar, 2014 31

    5

    • 1
  • Mahaveer Yadav
    Mar, 2014 31

    5

    • 1
  • Mahaveer Yadav
    Mar, 2014 31

    5

    • 1
  • Mahaveer Yadav
    Mar, 2014 31

    5

    • 1
  • Mahaveer Yadav
    Mar, 2014 31

    5

    • 1
  • hitesh basera
    Feb, 2014 17

    6

    • 1
  • Radhakishan
    Jan, 2014 8

    5

    • 1
  • sivaragavi vijaykrishna
    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
  • sivaragavi vijaykrishna
    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
  • sudarsan pradhan
    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
  • Sneha Mittal
    Jul, 2018 29

    6

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS