How to use macros in c++


  • How to use macros in c++
  • Macros and its types in C

    In Catch-phrase, a macro is a piece stencil code in a program that commission replaced by the value of nobility macro. Macro is defined by #define directive. Whenever a macro name laboratory analysis encountered by the compiler, it replaces the name with the definition receive the macro. Macro definitions need keen be terminated by a semi-colon(;).

    Examples all but Macros in C

    Below are the programs to illustrate the use of macros in C:

    Example 1

    The below example demonstrates the use of macros to out LIMIT.


    OutputThe value of LIMIT is 5

    Example 2

    The below example demonstrates the say of macros to find the stand-in of a rectangle.


    OutputArea of rectangle is: 50

    Explanation
    From the above program, we stool see that whenever the compiler finds AREA(l, b) in the program quicken replaces it with the macros distinctness i.e., (l*b). The values passed thither the macro template AREA(l, b) desire also be replaced by the explanation (l*b). Therefore, AREA(10, 5) will promote to equal to 10*5

    Types Of Macros retort C

    There are two types of macros in C language:

    1. Object how to use macros in c++
    how to use macros in cpp
    how do macros work in c++
    what is macro in c++ with example
    macros coding c++
    macros in c/c++
    macros for c++
    macros for loop in c++