Many has provided correct answer.
The Best way is to examine the assembly code.
printf("This is printf()n", f1(), f2());
// CALL f2
000213DE call f2 (21091h)
000213E3 mov esi,esp
000213E5 push eax
// CALL f1
000213E6 call f1 (21041h)
000213EB push eax
000213EC push offset string "This is printf()n" (25890h)
// CALL printf()
000213F1 call dword ptr [__imp__printf (282BCh)]
// return;
000213F7 add esp,0Ch
000213FA cmp esi,esp
000213FC call @ILT+320(__RTC_CheckEsp) (21145h)
Sequence of Function Execution
What is the sequence of function execution of the above statement.
1. printf, f1(), f2()
2. printf, f2(), f1()
3. f1(), f2(), printf
4. f2(), f1(), printf.
Profile Answers by pn_5449 Questions by pn_5449
Questions by pn_5449 answers by pn_5449
Editorial / Best Answer
mohinuddinkhanProfile Answers by mohinuddinkhan Questions by mohinuddinkhan
Let's understand this by going through the following code
#include<stdio.h>
int f1();
int f2();
void main()
{
printf("%dt%d",f1(),f2());
}
int f1()
{
printf("f1() enteredn");
return 4;
}
int f2()
{
printf("f2() enteredn");
return 5;
}
O/P-
f2() entered
f1() entered
4 5
we can conclude f2() is 1st executed
then f1() and in the end printf().hence we can say the precedence of execution of functions are from right to left.