GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  Concepts  >  OOPS

 Print  |  
Question:  what is the similarities between macro and function?



June 06, 2006 22:16:25 #6
 aptuz   Member Since: June 2006    Total Comments: 1 

RE: what is the similarities between macro and functio...
 

As Priya says from her straight shoot line, that makes sense.

A MACRO CAN CALL ANOTHER MACRO WITH IN ITS DEFINITION, PRETTY MUCH LIKE IN FUNCTIONS.

#define sq(x) x * x; // finds square of 'x'
#define cu(x) sq(x) * x; // finds cube of 'x'

Here a macro calls another macro, which is strticly possible. The similarity in functions could look like this.

int sq(int x) { return ( x * x ); }
int cu(int x) { return ( sq ( x ) * x ); }

would be a valid equivalent set of statements that could do the same functionality as that of above macros.

Hope tha HELPS!!!

     

 

Back To Question