What are macros in programming language ? And we use these macros and for which perpose.I saw a YouTube video and also read from a link but am cofused about why we use them.

  • $\begingroup$ Hi, IramShah, welcome to CSEd! I'm afraid that this question was closed because it's off-topic for our site, which focuses on how to teach effectively within a computer science classroom. I see that you already received a pretty good answer as well, so hopefully you have gotten the help that you need. $\endgroup$
    – Ben I.
    Commented Oct 27, 2018 at 2:26
  • $\begingroup$ Yes I got the answer actually am confused or want to clear about topic. $\endgroup$
    – Iram Shah
    Commented Oct 27, 2018 at 3:37

1 Answer 1


What macro are, and how the work, changes from language to language. That said, they are very generally a way to reuse code, often by doing searches and replacements within the code before it gets compiled or interpreted.

For example, in C and C++ you could type:

#include <string>

which is a macro asking for the entire contents of the file "string" to be placed where the #include instruction line is. That makes the code in that file available to the code in the file the programmer is writing, all with only one instruction.

Sometimes macros can also be used to make code easier to read or understand by either changing the name of something or by changing how certain code looks in specific situations. Macros can also be used to ensure code for some regularly occurring or complex task gets written properly.


Not the answer you're looking for? Browse other questions tagged or ask your own question.