Read only macro in c12/8/2023 ![]() Printf("circumference of a circle is: %d \n", circum) įrom the above-given code, pi is repeated two times in a program. In the formula 2*pi*r, the pi is replaced by the value 3.14, and the r value is declared in the program.Ĭonsider another example, where we have a macro name pi multiple times in the program. In this program, we will calculate a circle's circumference. Printf("circumference of a circle is: %f", circum) įrom the above-given code, 3.14 is a value of a macro name pi. Let’s look at the examples of how object-like macros are used in c. Generally, a defined value can be a constant numerical value. Object Like MacrosĪ macro is replaced by the value in object-like macros. Printf("Today's date is: %d/JULY/2022", date) Macros in c have functions like macros in which we can pass the arguments, which makes the program run faster. Rather than mentioning a piece of code repeatedly in the programs, we can define the constant value once and use it frequently. The program efficiency is increased by using Macros in c programs. Moving ahead, let us know the use of macros in c. Whenever the compiler encounters a macro name, it will replace it with the macro value. Syntax of a Macro:īelow we have an example program using macros in c Example Program:įrom the above code, “a” is a macro name and 10 is the value. Let’s look at the below-given syntax and how the macro is defined in c programs. ![]() In the macro definition, the macros are not terminated by the semicolon( ). ![]() ![]() Macro is a name given to a piece of code, so whenever the compiler encounters a macro in a program, it will replace it with the macro value. Macro in c is defined by the #define directive. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |