"Nothing in life is to be feared, it is only to be understood."
- Marie Curie
4.
Which of the following is the correct order if calling functions in the below code? a = f1(23, 14) * f2(12/4) + f3();
[A].
f1, f2, f3
[B].
f3, f2, f1
[C].
Order may vary from compiler to compiler
[D].
None of above
Answer: Option B
Explanation:
Here, Multiplication will happen before the addition, but in which order the functions would be called is undefined. In an arithmetic expression the parenthesis tell the compiler which operands go with which operators but do not force the compiler to evaluate everything within the parenthesis first.
() has the highest priority and it has left to right associativity so first f1, f2, f3 will be evaluated and then * is performed between the value returned from f1 and f2 and the + is computed with f3. So ans is A. Am I right?.
Sri Krishna said:
(Tue, Nov 1, 2011 07:26:12 PM)
The () doesn't have the highest precedence but grouping is more visible with high precedence operators. take a case:
int x=3,y=5,p=10,z;
z = (x>y)||(x==0)&&(y<<1);
printf("%d",z);
The output should be like (x>y)||(x==0) evaluated first and then the and operation. but as and has higher precedence, it forma a group leading to evaluation of (x>y) first and then anding with ((x==0)&&(y<<1)).
If you get the thing then try to answer the above question.
Nikita Sahane said:
(Sun, Jan 29, 2012 11:21:11 AM)
What will be the answer of above example you gave i.e. value of z ?