MACROS in C Questions and Answers
Question-1 What is a macro in C?
Answer- Macros are essentially shorthand representations of arbitrary sections of the source code, which makes the source code succinct, while its (the macro template’s) expansion replaces each of its presence prior to compilation. Whatever is there to do with Macros, it is done by the preprocessor, so that the source code is ready for compilation.
Question-2 How would you invoke a macro?
Answer- After defining a macro, we can invoke it by adding the percent sign prefix to its name like this: % macro name a semicolon is not required when invoking a macro, though adding one generally does no harm.
Question-3 What is the difference between %LOCAL & %GLOBAL?
Answer- %LOCAL is a macro variable defined inside a macro. %GLOBAL is a macro variable defined in open code (outside the macro or can be used anywhere)
Question-4 Can you execute macro within another macro?
Answer- Yes, I can execute macro within a macro, we call it as nesting of macros, which is allowed. Every macro’s beginning is identified the keyword %macro and end with %mend.
Question-5 What is the difference between macros and prompt?
Answer- Macros is a run time object, used with parameter map and session parameters to create conditional query subjects.
Prompt is nothing but a Dynamic filter, which will restrict the data displayed in report.
Question-6 What are Syntactic macros?
Answer- Macro systems that work at the level of abstract syntax trees are called syntactic macros and preserve the lexical structure of the original program. Meanwhile, macro systems, such as the C preprocessor described earlier, that work at the level of lexical tokens cannot preserve the lexical structure reliably. The most widely used implementations of syntactic macro systems are found in Lisp-like languages such as Common Lisp, Scheme, ISLISP and Racket. These languages are especially suited for this style of macro due to their uniform, parenthesized syntax (known as S-Expressions). In particular, uniform syntax makes it easier to determine the invocations of macros. Lisp macros transform the program structure itself, with the full language available to express such transformations. While syntactic macros are most commonly found in Lisp-like languages, they have been implemented for other
Question-7 What is a NULL macro?
Answer- NULL macro is defined in stdio.h and stddef.h. It is used to represent a null pointer in your code. Its value is zero.
Question-8 What are the differences between macros and Functions in C language?
1. Macros in C consumes less time. When a function is called, arguments have to be passed to it, those arguments are accepted by corresponding dummy variables in the function, they are processed, and finally the function returns a value that is assigned to a variable (except for a void function). If a function is invoked a number of times, the times add up, and compilation is delayed. On the other hand, the macro expansion had already taken place and replaced each occurrence of the macro in the source code before the source code starts compiling, so it requires no additional time to execute.
2. Function in C consumes less memory. While a function replete with macros may look succinct on surface, prior to compilation, all the macro-presences are replaced by their corresponding macro expansions, which consumes considerable memory. On the other hand, even if a function is invoked 100 times, it still occupies the same space. Hence function is more amenable to less memory requirements.
Question-9 What is the difference between a null pointer and a null macro?
Answer- Null macro is #define NULL 0.
It means the macro null will be replaced by 0 while preprocessing but the NULL pointer means it points to nowhere i.e contains 0 means it may be dangerous to use such pointer without assigning proper address to it. Otherwise null pointer may try to access reset address may cause the program to crash.
Question-10 What is the difference between Macro and #define?
Answer- A macro is a placeholder name for a complex definition. You use the macro name instead of the having the complex definition duplicated. In C and C++ macros are identified by the symbol following by #define.
For an example: #define MAX 10
Here MAX is a macro which is a placeholder for 10. If you use MAX in your code, the preprocessor will change it to 10 before sending your code to the compiler.
this post will increase your knowledge in the field of c lang.
Those who are having some interest in this topic or wan to collect details on it go thru this valuable article…………..
Know about the Macros in the C Language in the detail with the pictures to make you understand easily and effectively.
the above questions consists of few important questions of macros in c .for the ones who are interested go through the details.