This depends on how the compiler evaluates the actual parameters and push to the stack when printf is called. this is totally depeding on the compiler architecture [ basically implemetion of activation record in intermediate code genaration phase, read intermidiate language and virtual machine @ compiler design by Aho ullman]
In dev C++, the printf works as below: they evalute expression from right to left and push back into stack. thus the expression printf("%d %d %d %d",++p,p++,p++,++p); evaluted as below: initially p=1; printf("%d %d %d %d",++p,p++,p++,2);//p=2 as prefix printf("%d %d %d %d",++p,p++,2,2);//p=3 as postfix printf("%d %d %d %d",++p,3,2,2);//p=4 again postfix printf("%d %d %d %d",5,3,2,2);//p=5 here prefix.. as now our stack contaion 5,3,2,2 ..it print's as this... some more example as : printf("%d %d %d %d %d",++ p,p++,p++,++p, p++); output:6 4 3 3 1 printf("%d %d %d %d %d",++ p,p++,p++,p++, p++); output: 6,4,3,2,1 printf("%d %d %d %d %d",++p,p--,--p,p++, p--); output: 0 0 0 0 1 On 7/18/11, keyan karthi <keyankarthi1...@gmail.com> wrote: > thanks ppl :) > > On Mon, Jul 18, 2011 at 3:59 PM, schrodinger > <6fae1ce6347...@gmail.com>wrote: > >> AFAIK, official answer is "due to undefined behavior". >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To view this discussion on the web visit >> https://groups.google.com/d/msg/algogeeks/-/EAWuaDE1CIcJ. >> >> To post to this group, send email to algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- Thanks and Regards, ------------------------------ **DIPANKAR DUTTA Software Development Engineer Xen Server - OpenStack Development Team (DataCenter and Cloud) Citrix R&D India Pvt Ltd 69/3, Millers Road, Bangalore – 560052 Phone: +91 9045809987 Office: Extn: 16429 Email: dipankar.du...@citrix.com -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.