pranjal kumbang


{ City } jorhat,assam
< Country > india
* Profession * student
User No # 96040
Total Questions Posted # 0
Total Answers Posted # 1

Total Answers Posted for My Questions # 0
Total Views for My Questions # 0

Users Marked my Answers as Correct # 8
Users Marked my Answers as Wrong # 2
Questions / { pranjal kumbang }
Questions Answers Category Views Company eMail




Answers / { pranjal kumbang }

Question { 27955 }

void main()
{
int a=1;
printf("%d %d %d",a,++a,a++);
}
the output is supposed to be 1 2 2....but it is 3 3 1
this is due to calling conventions of C. if anyone can
explain me how it happens?


Answer

Output:3 3 1 This
is because,C's calling convention is from right to left.That
is ,firstly 1 is passed through the expression a++ and then
a is incremented to 2.Then result of ++a is passed.That is,a
is incremented to 3 and then passed.Finally,latest value of
a,i.e. 3,is passed.Thus in right to left order,1 ,3, 3 get
passed.Once printf() collects them,it prints them in the
order in which we have asked it to get them printed(and not
the order in which they were passes).thus 3 3 1 gets
printed.

Is This Answer Correct ?    8 Yes 2 No