37
Reply

what will be the value of b?? int a = 2; int b = a++ + a++;

Vivek Sharma

Vivek Sharma

Sep 18, 2013
153.2k
0

    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.

    sudarsan pradhan
    September 24, 2013
    1

    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 | +-----+-----+------+------+----+

    Vivek Sharma
    September 18, 2013
    1

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

    Ramesh S
    December 01, 2016
    0

    a= 4 and b = 5

    Ramesh S
    December 01, 2016
    0

    a= 4 and b = 5

    Ramesh S
    December 01, 2016
    0

    a= 4 and b = 5

    Ramesh S
    December 01, 2016
    0

    a= 4 and b = 5

    Ramesh S
    December 01, 2016
    0

    a= 4 and b = 5

    Ramesh S
    December 01, 2016
    0

    a= 4 and b = 5

    Ramesh S
    December 01, 2016
    0

    a= 4 and b = 5

    Ramesh S
    December 01, 2016
    0

    a= 4 and b = 5

    Ramesh S
    December 01, 2016
    0

    a= 4 and b = 5

    Ramesh S
    December 01, 2016
    0

    a= 4 and b = 5

    Ramesh S
    December 01, 2016
    0

    a= 4 and b = 5

    Ramesh S
    December 01, 2016
    0

    a= 4 and b = 5

    Ramesh S
    December 01, 2016
    0

    a= 4 and b = 5

    Ramesh S
    December 01, 2016
    0

    a= 4 and b = 5

    Ramesh S
    December 01, 2016
    0

    value of a= 4 and b = 5

    Anil Kumar Murmu
    February 05, 2016
    0

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

    Nachiappan NK
    June 16, 2015
    0

    5

    Rahul Prajapat
    May 27, 2015
    0

    b=5

    Manoj Bhoir
    April 29, 2015
    0

    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;

    Anil
    April 29, 2015
    0

    4

    4

    Bhawna Raghuvanshi
    September 17, 2014
    0

    5

    Divendra Ojha
    July 17, 2014
    0

    5

    Bhabani Prasad
    May 24, 2014
    0

    5

    Mahaveer Yadav
    March 31, 2014
    0

    5

    Mahaveer Yadav
    March 31, 2014
    0

    5

    Mahaveer Yadav
    March 31, 2014
    0

    5

    Mahaveer Yadav
    March 31, 2014
    0

    5

    Mahaveer Yadav
    March 31, 2014
    0

    5

    Mahaveer Yadav
    March 31, 2014
    0

    6

    hitesh basera
    February 17, 2014
    0

    5

    Radhakishan
    January 08, 2014
    0

    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();

    sivaragavi vijaykrishna
    December 18, 2013
    0

    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();

    sivaragavi vijaykrishna
    December 18, 2013
    0

    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.

    sudarsan pradhan
    September 24, 2013
    0