Define macros. Advantages and disadvantages of Macros

Define macros. What are the advantages and disadvantages of Macros?

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.
Pass by reference vs. pass by value
Pass by value always invokes / calls the function or returns a value that is based on the value....
Define static identifier in C
The static identifier is used for initializing only once, and the value retains during the life time of the program / application....
What are the auto variables? Where are they stored?
The auto variables are stored in the memory of the system. The keyword ‘auto’ is optional......
Post your comment
Discussion Board
Difference between size and lenght:
Size means the no of bytes the program is occupying, while the length is the no. of lines used.
himanshu yadav 09-6-2014
C Macro
The size of the program is the no of machine code bytes generated by the code. Length of the program is the no. of lines written in the hi level language.
V Durgai 02-21-2014
what is the difference between size of the program and length of the program
vishnu 09-12-2013

You may like