UrbanPro

Learn C Language from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

What is a macro, and how do you use it?

Asked by Last Modified  

Follow 1
Answer

Please enter your answer

Professional Tutor with 15 years of experience.

A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro. There are two kinds of macros. They differ mostly in what they look like when they are used. Object-like macros resemble data objects when used, function-like macros resemble...
read more
A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro. There are two kinds of macros. They differ mostly in what they look like when they are used. Object-like macros resemble data objects when used, function-like macros resemble function calls. read less
Comments

Tutor of programming language and tutor of I-V and VI-VII

A macro is a name given to a block of C statements as a pre-processor directive. Being a pre-processor, the block of code is communicated to the compiler before entering into the actual coding (main () function). A macro is defined with the preprocessor directive, #define. Before compilation, the name...
read more
A macro is a name given to a block of C statements as a pre-processor directive. Being a pre-processor, the block of code is communicated to the compiler before entering into the actual coding (main () function). A macro is defined with the preprocessor directive, #define. Before compilation, the name of macro is replaced by the defined macro body. The speed of the execution of the program is the major advantage of using a macro. Disadvantage: The size of the program is large. Example: #include"stdio.h" #define X 100 void main() { printf("%d",X); } read less
Comments

Oracle, Hindi, C++, C, MS Office, VBScript,JavaScript,Spoken English etc with 31 years of experience

Macros automate frequently-used tasks; many are created with VBA and are written by software developers. However, some macros pose a potential security risk.
Comments

printf ("File Name = %s.\n",__FILE__);
Comments

Professional Trainer:: Hadoop Big Data, DevOps, Perl, Python

macro is single line code block, e.g. #define area(r) (3.1415*(r)*(r)) where ever you refer to the macro area(r), it will be replace with the actual code block defined in macro radius=10; area=area(radius); so in the above code the macro is replaced with the actual code area=(3.1415*(radi...
read more
macro is single line code block, e.g. #define area(r) (3.1415*(r)*(r)) where ever you refer to the macro area(r), it will be replace with the actual code block defined in macro radius=10; area=area(radius); so in the above code the macro is replaced with the actual code area=(3.1415*(radius)*(radius)) read less
Comments

Tutor

Gcc website says "A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro." In our terms, A macro is something prefixed by a # and used be preprocessor. There are various macros like define,ifdef,ifndef,if,include etc. Its very...
read more
Gcc website says "A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro." In our terms, A macro is something prefixed by a # and used be preprocessor. There are various macros like define,ifdef,ifndef,if,include etc. Its very easy to use but you must understand when to use one. read less
Comments

Tutor

Macro is a very useful construct. Basically it is a piece of code with name. Macros are declared using #Define preprocessor directive. these are used to define constants as well as functions. e.g. pi is a constant hence instead of declaring it as a variable like float pi=3.14 it can be declared as...
read more
Macro is a very useful construct. Basically it is a piece of code with name. Macros are declared using #Define preprocessor directive. these are used to define constants as well as functions. e.g. pi is a constant hence instead of declaring it as a variable like float pi=3.14 it can be declared as a constant like #Define pi 3.14. e.g. #Define area(l,b) (2(l+b)) whenever pi or area(l,b) will be used they will expand to 3.14 and (2(l+b)). user has to pass the appropriate value for l(length) and b(breadth) i.e. whenever the compiler find a macro name it replaces the name with its contents. A macro is accessible to all the functions of the program. e.g. if pi is defined as a variable then it will be accessible by the function where it is declared but if declared using #Define then it is accessible by all the functions of the program. read less
Comments

Macro is a preprocessor directive we can give any name to any thing it doesn't give any errors compailer replace that names preprocessor stage only
Comments

International Corporate Trainer For dotnet Core ,Angular 2 ,C ,C++ and LPT Marathi for RBI Banking

Macro in C is also called symbolic constant , it replaces the code part. ex:#define line "\n..................\n", ex: #define Square(x) (x)*(x), this is called function macro it will work as Square(5) = 25 but it is not type safe user may enter alphabet instead of number and progam will fail. better...
read more
Macro in C is also called symbolic constant , it replaces the code part. ex:#define line "\n..................\n", ex: #define Square(x) (x)*(x), this is called function macro it will work as Square(5) = 25 but it is not type safe user may enter alphabet instead of number and progam will fail. better way is to use user defined function read less
Comments

In simplest form think of Macro as search and replace by pre-processor: example: #define MAX(a,b) a>b?a:b void f() { int i=5; int j=3; int m = MAX(i,j); }
Comments

View 14 more Answers

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Looking for C Language Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for C Language Classes?

The best tutors for C Language Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn C Language with the Best Tutors

The best Tutors for C Language Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more