0% found this document useful (0 votes)
29 views8 pages

Nested Macros: Presented By: Ishita Sharma Student Of: Trinity Institute of Professional Studies

Uploaded by

ishitaasharma2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views8 pages

Nested Macros: Presented By: Ishita Sharma Student Of: Trinity Institute of Professional Studies

Uploaded by

ishitaasharma2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Nested

Macros
P R E S E N T E D B Y: I S H I TA S H A R M A
S T U D E N T O F: T R I N I T Y I N S T I T U T E O F P R O F E S S I O N A L S T U D I E S
Introduction to
Macros
Exampl
A macro is essentially a
e -
#include <stdio.h>
piece of code or a value that
// Define a macro for the value of pi
is associated with an #define PI 3.14
identifier. It is defined using int main() {
double radius = 5.0;
the #define preprocessor double area = PI * radius * radius;
printf("The area of the circle is: %lf\
directive. n", area);
return 0;
}
OUTPUT: The area of the circle is: 78.50
Types of Macros
• Object-like macros replace code with meaningful
Object like macro names, improving readability. They simplify
maintenance by allowing changes in one place,
reducing repetition and errors
• Function-like macros act like functions, taking
inputs to perform tasks and enable code reuse.
Function-Like Macros They simplify development, reduce repetition, and
improve coding efficiency and productivity..

• Chain-like macros let you use one macro inside


Chain-Like Macros another. They are processed step-by-step, making
complex coding tasks easier.
What are Nested Macros?
A nested macro in C is a macro
instruction definition that is
specified as a set of model
statements in the body of an
enclosing macro
definition. This allows the
creation of a macro definition
by expanding the outer macro
that contains the nested
definition.
#include <stdio.h>
// Define a basic macro

#define SQUARE(x) ((x) * (x))


// Define another macro that uses the first one (nested
macros)

#define CUBE(x) (SQUARE(x) * (x))


How int main() {

Nested int num = 3;


printf("Square of %d is: %d\n", num,
Macros SQUARE(num));
printf("Cube of %d is: %d\n", num, CUBE(num));
Work return 0;
}
OUTPUT:
Square of 3 is: 9
Cube of 3 is: 27
Advantages and Limitations
of Nested Macros
ADVANTAGES LIMITATIONS
•Increased Efficiency and •Complexity and Difficulty to
Productivity Maintain
•Enhanced Customization and •may cause unexpected problems
Control •Increased Resource
•Reduced Risk of Errors and Requirements
Inconsistencies
Conclusion
NESTED MACROS LET YOU L AYER AUTOMATION TO
STREAMLINE REPETITIVE TASKS. BUT YOU NEED TO DESIGN
THEM CAREFULLY TO AVOID COMPLEXITY
THANK YOU FOR YOUR
ATTENTION

You might also like