#define SQR(x) x * xmain(){ printf("%d", 225/SQR(15));}

A) 15
B) 225
C) 1
D) none of the above

Showing Answers 1 - 12 of 12 Answers

Rohit

  • Dec 14th, 2005
 

225

  Was this answer useful?  Yes

mef526

  • Feb 13th, 2006
 

Use typical C coding guidelines and use

#define SQR(x) ((x) * (x))

And you get the desired answer: 1

  Was this answer useful?  Yes

arjun

  • May 23rd, 2006
 

hi,in C, '*' has got higher precedence than '/', so the execution will be some what like this225/(15 * 15) hence the answer will be 1...;-)

  Was this answer useful?  Yes

ramamaru

  • May 24th, 2006
 

Arjun u r wrong....Refer to michael's comment...

  Was this answer useful?  Yes

yba

  • Jul 10th, 2007
 

In algebra * has higher precedence than /, but in C they have the same precedence, and are left-associative, meaning the operations are performed left to right.

So 225 / 15 * 15 gives (225/15)*15 or 225.

It is hard to say what intent is in this question, the intent is probably to trip you up.  Let us hope that is not the intent in real code, and that you use the form

#define SQR(x) ((x)*(x))

Because the next question might be what is the value of 225/SQR(3 * 5) ?

Inline functions are a lot safer than macros.

Yes the answer will be 225/15*15. As / and * has the same precedednce and associativity is from left to right so it will give 225(225/15*15 => 15*15 => 225).

  Was this answer useful?  Yes

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