-1

Suppose i have the following code:

#include <stdio.h>    
main()
{
   int a,b,c;
    b=1;
    c=2;

    printf("%d\n",10,b=20,b=30,c=50,c=100);
    printf("%d\n",b);
    printf("%d\n",c);
}

o/p-10,20,50 how did the value of b became 20,not 30 ..and also the same for c?

Bas
  • 4,423
  • 8
  • 36
  • 53

1 Answers1

2

The order of evaluation of argument expressions and their pushing on the stack are different things.

The order of evaluation of argument expressions are unspecified in C. So it might be that at first b = 20 will be evaluated and then b = 30 or vice versa.

The order of placing arguments in the stack is the following: the right most argument is placed first.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
  • 1
    +1'd,To clarify more--->shouldn't it be `The order of placing arguments in the stack is the following: the right most argument is placed at the bottom.` – Am_I_Helpful Sep 14 '14 at 09:37
  • It depends on the ABI - some don't even use the stack, or use a mixture of registers and stack. – Paul R Sep 14 '14 at 09:45
  • Even worse, this is multiple assignments to one location without intervening sequence point, so it is undefined behaviour. – Vatine Sep 14 '14 at 10:06