Examveda
Examveda

Consider the following program fragment, and choose the correct one.
void main()
{
   int a, b = 2, c;
   a = 2 * (b++);
   c = 2 * (++b);
}

A. a = 4, c = 8

B. a = 3, c = 8

C. b = 3, c = 6

D. a = 4, c = 6

E. b = 4, c = 6

Answer: Option A


This Question Belongs to C Program >> Operators And Expressions

Join The Discussion

Comments ( 3 )

  1. Prathamesh Kiran
    Prathamesh Kiran :
    2 years ago

    Frist b++ is 2 now Frist ans is 2*2=4
    NOW it's a increment operator then Frist b++ and ++b it's two times increment that's way b=4
    B++ is Frist assign the value again increment this is postinremnt that's way after ans this is 3 and ++b is b=b+1 this is 4

  2. Harshal Chaudhari
    Harshal Chaudhari :
    6 years ago

    Plz explain this pro

  3. Sagar Gurao
    Sagar Gurao :
    7 years ago


    b++ = 3 in 1st condition
    ++b =4 due to 1st condition

Related Questions on Operators and Expressions