what are macros?what are its advantages and disadvantages in
c language?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

why we use conio.h in c programming?

1679


Can one be shocked holding a wire carrying a very large current with a low voltage source?

1559


Are bridges more stable on concrete or on soil - why?

872


what is b tree

1590


Explain momentum?

605






hi friends i am first time using this site.i came to by some tcs personals that certifications r important for placements.i am financially average i am learning java from books.please tell is it enough if not which certification should i go for

1341


reduce the number of key strokes to execute this command : t char -t -v -f/dev/fd0

3051


how to implement spiral model on railway reservation?.

2614


a steel bar 1' inch square 6' long is to be used as a column.ends are free to rotate put may not be displaced.stress is limited to 30,000 PSI

1385


5. Tell me about a time you were able to successfully deal with another person even when that individual may not have personally liked you (or vice versa).

1575


what is mean by tranducer

1640


What is the weight of a foot square block of bronze.

1261


Write a shell script to delete all files present in a directory “dir1”. Any error, if it occurs while carrying out this operation should be stored in a file errorlog

1595


Hi, I am appearing for the ISRO exam for the post of Scientist/ Engineer to be held on 26th April,09. Can anyone help me regarding the same? I want to know about the exam pattern and the syllabus. If anyone could share your experience or sample papers for the same at khadhar786@rediffmail.com? It would be very useful for me. Thanks.

1677


hi i am avinash ,i am doing ma b-tech(cse) final year and i have been detained for 2years due to attendance and i will be finished ma b-tech in 6 years ,plz tell me weather i will be eligible for government jobs like bhel, drdo,or any other private companies

1346