0

I came across the calling conventions of C and by default the arguments are passed from right to left. So as per that first a++ will be passed that is the value 2 will be passed and also the value of a is now is 2 and after that ++a will be passed which is 3 and the value of a will now be 3 and in the last a will be passed. My question is when ++a and a++ have already been passed the value of a has been changed to 3. So should'nt the o/p for this code snippet be 3 3 3 rather than 3 3 1 which got after running the code.

#include<iostream>
{
int a=1;
printf("%d%d%d",a,++a,a++);
}
Rohit Saluja
  • 1,517
  • 2
  • 17
  • 25
  • The order of evaluation of the arguments in printf aren't specified! – Rizier123 Jan 02 '15 at 10:02
  • 2
    It's *undefined behaviour* since you are modifying `a` more than once between two sequence points. It's been asked plenty of times before... – P.P Jan 02 '15 at 10:03
  • 1
    Calling conventions are irrelevant here. Order of evaluation is. And order of evaluation for function arguments is unspecified. So you've got undefined behavior. – Mat Jan 02 '15 at 10:12

0 Answers0