GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Tech FAQs  >  OOPS
Go To First  |  Previous Question  |  Next Question 
 OOPS  |  Question 232 of 258    Print  
what is meant by macros?
how it works?
what is the out put of the program
#define sqr(x) x*x
void main()
{
int a,b=3;
a=sqr(b+2);
cout<}

  
Total Answers and Comments: 3 Last Update: September 12, 2006     Asked by: sumanthreddy 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
August 11, 2006 04:39:51   #1  
muthu        

RE: what is meant by macros?how it works?w...

hi friends

macros:

i like to share my views regarding macros (i.e ) macro is an abstraction that defines how a certain input pattern is replaced by an output pattern according to a defined set of rules. they are used to automate the frequently used words in keyboard strokes or mouse movements.

how it works:

they are implemented as preprocessors in machines.

the output for the above program is :

25.

because the value of b goes to the equation and gets substituted and the entire value of 5 is made square root using macros and the final output is

5*5 25 gets printed


 
Is this answer useful? Yes | No
August 25, 2006 12:13:55   #2  
Harman        

RE: what is meant by macros?how it works?w...

Hi

The output is 11. To solve it fo not confuse yourself with scoctamic thinking.instead macro is just an alias or replacement.

so when you define sqrx(x) as x*x.then at every place where it will find sqrx(x) it will replace it with x*x.

so sqrx(B+2) will replace to (b+2*b+2) now apply bodmas and solve it

(3 +2*3+2) (3+6+2) 11.

and mind it 25 is not correct answer.you can verify my answer


 
Is this answer useful? Yes | No
September 12, 2006 04:32:18   #3  
prema        

RE: what is meant by macros?how it works?w...

The output is 11. Macro is a preprocessor directive. During preprocessing the preprocessor replaces every occurence of x with x*x.

In this case we have b+2 in place of x. so x*x means b+2*b+2.

here b holds the value 3.

hence it becomes (3+2*3+2)

Multiplication has got more precedence than addition. Hence multiplication takes place first and then the addition. So it's (3+6+2).

Hence the output is 11.


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape