What is Macro? Why do we use the macro?

Long Answer
Views 887

Answer:

  • Macro is a name which is given to a value or to a piece of code/block in a program. Instead of using the value, we can use macro which will replace the value in a program.
  • The reason for using macro is, consider below example.
  • You are using a person’s age as 50 in many places in your program. If you use direct value in all the places in your program, it is very difficult to change the age value in future if you want to change it to 60. If you use macro in your program, it is very simple to replace the value and we can change in only one place which will change the value in all places in your program.

Syntax: #define <MACRO_NAME> VALUE
Example:
Original declaration – #define AGE 50
Modified declaration – #define AGE 60

Related Articles:

This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of C Programming Language, click the links and dive deeper into this subject.

Join Our telegram group to ask Questions

Click below button to join our groups.