In the following code, in which order the functions would be called?x = f1(23,14)*f2(12/4)+f3();a) f1, f2, f3 b) f3, f2, f1c) The order may vary from compiler to compiler d) None of the above

Choose the correct option

Questions by Lokesh M   answers by Lokesh M

Showing Answers 1 - 7 of 7 Answers

Amit

  • Dec 17th, 2005
 

C)The order may vary from compiler to compiler in C in which order function will be called depends on compiler.

  Was this answer useful?  Yes

paulson paul chambakottukudyil

  • Apr 20th, 2006
 

All the compilers follow the operator presidence for math operations. ie, * have a higher precidence than +. It is a mathematical rule, don't vary with compiler. so, to evaluate the * operation, f1 will be called first followed by f2. then f3 will be called.

yba

  • Jul 10th, 2007
 

Operator precedence tells you which operations bind the tightest, but it says nothing about the order in which commutative or associative operations must be carried out by the compiler.  According to the ISO and ANSI standards, a compliant compiler can carry out the operations in any order it likes, so we have to answer (c).

In this example, I could geenrate code that calls f3, store the result in a register, call f2, store the result in a register, call f1 and store the result in a register, and then correctly multiply the register result of f1*f2 and add the register result from f3.  Precedence is followed, but the order of the function calls was f3,f2,f1, and I am still compliant with the standard.  I can call them in any order, so long as I combine the results as specificed by the language.


Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions