Briefly explain macro function

Systems Architecture
7th Edition
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Stephen D. Burd
Chapter10: Application Development
Section: Chapter Questions
Problem 5VE
icon
Related questions
Question

Briefly explain macro function

Expert Solution
Step 1

Macro function

Macros are generally used in C/C++ programming language. They refer to the name given to a value (or a segment of code). Whenever that name is used in a program, it will be replaced by the value of that macro. It is usually a one-line statement that appears at the beginning of the program.

Macros are defined in the program using the #define preprocessor directive which precedes by valid identifier name and value as a numeric or string that must be substituted by the preprocessor whenever that macro encounters in the program.

For example:

#define PI 3.14  
where PI is the name of the macro which will be replaced by the value 3.14 in the program.

The macros that are accepting arguments and return values are called function-like macros

For example:

The following macro is defined with one argument. Whenever areaOfCircle(argument) occurs in a program, it will be replaced by (3.14*(argument)*(argument)).

#define areaOfCircle(radius) (3.14*(radius)*(radius))

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Module hierarchy chart
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage