Question
Please help me for this homework problem, thanks!! Read text section 1.4.2. Macros are available in most high-level programming languages. The body of a macro
Please help me for this homework problem, thanks!!
- Read text section 1.4.2. Macros are available in most high-level programming languages. The body of a macro is simply used to replace a macro-call during the preprocessing stage. A macro introduces a "true inline" function that is normally more efficient than an "outline" function. However, macros suffer from the side-effect, unwanted, or unexpected modifications to variables. Macros should be used cautiously. The main purpose of the following programs is to demonstrate the differences between a function and a macro. Other purposes include demonstrating the differences between different programming environments, and learning different ways of writing comments, formatted input and output, variable declaration and initialization, unary operation ++, macro definition/call, function definition/call, if-then-else and loop structures, etc.
Observe each of the functions below and understand their functionality. You can use either
GNU gcc under Unix or Visual Studio to implement the code in this question
int subf(int a, int b) {
return a - b;
}
int cubef(int a) {
return a * a * a;
}
int minf(int a, int b) { if (a <= b) {
return a;
}
else {
return b;
}
}
int oddf(int a) { if (a % 2 == 1) { return 1;
}
else {
return 0;
}
2.1 Write four macros to re-implement the given four functions. Name them: subm, cubem, minm, and oddm, respectively. [10 points]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started