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.
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:
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.