Working of printf statement in C
void func(int x, int y){}
main()
{
func(printf("kill"),printf("hello"));
getch();
}
So what is the reason that the right printf value gets printed here then left one executes.
Administrator • Feb 22, 2015
evaluation of the arguments depends completely on the compilerYour answer lies in this statement that you wrote.
Member • Feb 23, 2015
But Mam ,I studied that we need to follow the standard the function arguments are executed from right to left ,so although I too agree with this fact that it is completely dependent on compiler ,but what if I get any MCQ so then on which option to click depending on the right to left order evaluation or unspecified option.Ankita KatdareYour answer lies in this statement that you wrote.
The output of your program will completely depend on your compiler.
For example, a function call like below may very well behave differently from one compiler to another:
void func (int, int);
int i = 2;
func (i++, i++);
Output could be either: '2, 3' or '3, 2'
It is never safe to depend on the order of evaluation.
Administrator • Feb 23, 2015
Member • Feb 23, 2015
The parameters are pushed from right to left (so that the first parameter is nearest to top-of-stack), and the caller cleans the parameters.So while pushing from right to left, you will get right one to print first.
Member • Feb 25, 2015