what are macros?what are its advantages and disadvantages in
c language?
Answers were Sorted based on User's Feedback
Answer / ravi ranjan
A macro is a name given to a block of C statements as a
pre-processor directive. Being a pre-processor, the block of
code is communicated to the compiler before entering into
the actual coding (main () function). A macro is defined
with the preprocessor directive, #define.
Like::: #define A 10
#define SUM(x,y) ((x) + (y))
Advantages :::
1.Symbolic constants are evaluated by the PRE-processor,
i.e. they are re-written as literal values, not as
variables. this has some nice side-effects that you can do
using symbolic defines eg. macros and functions inside them.
run-time access to symbolic constants should be
significantly faster than access to variables.
opposite to that, variables (and constants) are evaluated by
the processor (compiler).
2. It is easy to modify the value of the constant
variable,since we have to change the value at the macro
defintion only
DisAdvantages:::
1. Macros are not useful when the function definitions are
Big and when the function is used many number of times.
Is This Answer Correct ? | 52 Yes | 14 No |
Answer / deepedra kushwaha
A macro is a name given to a block of C statements as a
pre-processor directive. Being a pre-processor, the block of
code is communicated to the compiler before entering into
the actual coding (main () function). A macro is defined
with the preprocessor directive, #define.
The advantage of using macro is the execution speed of the
program fragment. When the actual code snippet is to be
used, it can be substituted by the name of the macro. The
same block of statements, on the other hand, need to be
repeatedly hard coded as and when required.
The disadvantage of the macro is the size of the program.
The reason is, the pre-processor will replace all the macros
in the program by its real definition prior to the
compilation process of the program.
Describe the advantages of using macro.
A macro is a name given to a block of the code which can be
substituted where the code snippet is to be used for more
than once.
- The speed of the execution of the program is the major
advantage of using a macro.
- It saves a lot of time that is spent by the compiler for
invoking / calling the functions.
- It reduces the length of the program.
Is This Answer Correct ? | 16 Yes | 11 No |
what is total power generation capacity in india at present (as on 12-12-2011)
What is the relation between dB and change of signal?
when did actually oil exploration start
4) Write a program that takes a 5 digit number and calculates 2 power that number and prints it. I did the following program and is this correct
what are the various height of GSM mount and its base width ashim.port@gmail.com
please send me last 2 years solved IIT papers
print your name without using any semicolon?
describe about storage allocation and scope of global,exterm,static,local and register variables in c language?
What is saturation point?
Difference in NS and TIA type HRC fuses
display the second highest salary department wise in employee table
wat is the process of civil services examination...I want to become DSP....Is civil services and APPSC are sam???first of all for wat we have to prepare...for prelimnary or for mains or for nterview...i dont know any thing...please help me...arun.kanduri@gmail.com