Examveda
Examveda

What is the output of the following statements?
int i = 0;
printf("%d %d", i, i++);

A. 0 1

B. 1 0

C. 0 0

D. 1 1

E. None of these

Answer: Option B

Solution(By Examveda Team)

Since the evaluation is from right to left.
So when the print statement execute value of i = 0
Since its execute from right to left when i++ will be execute first and print value 0 (since its post increment ) and after printing 0 value of i become 1.
So it its prints for 1 for next i.

This Question Belongs to C Program >> Operators And Expressions

Join The Discussion

Comments ( 11 )

  1. Mounota Hossain
    Mounota Hossain :
    2 years ago

    int i = 5;
    printf("%d %d", --i, i++)

  2. Parag Mardhekar
    Parag Mardhekar :
    2 years ago

    it will print 0 na first

  3. Amit Tiwari
    Amit Tiwari :
    6 years ago

    okay you have used stack property but how is 0 increemented before the completion of the statement?

  4. Adff Ss
    Adff Ss :
    7 years ago

    but parenthesis associativity is left to right.

  5. Examveda
    Examveda :
    7 years ago

    Umang! explanation already clear enough to understand. please read it and understand it. and run the above code to be sure about the answer.

  6. Umang Mahant
    Umang Mahant :
    7 years ago

    if it prints 0 before 1 then ans should be A... how can u say B? Please Explain!!!

  7. Umang Mahant
    Umang Mahant :
    7 years ago

    how?? is it wrong?

  8. Examveda
    Examveda :
    7 years ago

    Answer updated. Please review for better clarification.

  9. Agnes Pious
    Agnes Pious :
    7 years ago

    how??

  10. Arun Kumar
    Arun Kumar :
    8 years ago

    i cant understand clearly...
    please explain with each step...

  11. Riti Thakur
    Riti Thakur :
    8 years ago

    I THINK IT MAY BE 1,1 IF EVALUATION FROM RIGHT TO LEFT

Related Questions on Operators and Expressions