Join our subscribers list to get the latest news, updates and special offers directly in your inbox
Overview
Macros Operations
Bitwise Operations
Functions
Ans: A macro is a preprocessor directive in C that defines a symbolic name or constant value that can be used throughout the program.
Ans: The syntax for defining a macro in C is as follows:
#define MACRO_NAME macro_value
Ans: A macro is a preprocessor directive that is expanded at compile time, while a function is a code block that is executed at runtime.
Ans: To use a macro in C, simply write its name wherever user want to use its value in the program.
Ans: The #ifdef directive is used to check if a macro has been defined in the program. If the macro has been defined, the code block between #ifdef and #endif is executed.
Ans: The #ifndef directive is used to check if a macro has not been defined in the program. If the macro has not been defined, the code block between #ifndef and #endif is executed.
Ans: The #undef directive is used to undefine a macro that has been previously defined in the program.
Ans: The #include directive is used to include a header file in the program that contains declarations for functions, variables, and macros used in the program.
Ans: Arguments can be passed to a macro by enclosing them in parentheses after the macro name. For example:
#define ADD(a, b) ((a) + (b))
Ans: Strings can be concatenated in a macro using the ## operator. For example:
#define CONCAT(a, b) (a##b)
#include <stdio.h> #define MAX 100 int main() { printf("The value of MAX is %d\n", MAX); return 0; }
#include <stdio.h> #define ADD(a, b) ((a) + (b)) int main() { int num1 = 10, num2 = 20, sum; sum = ADD(num1, num2); printf("The value of sum is %d\n", sum); return 0; }
#include <stdio.h> #define SQUARE(x) ((x) * (x)) int main() { int num = 5, sq; sq = SQUARE(num); printf("The square of %d is %d\n", num, sq); return 0; }
EmbeddedWala Apr 27, 2023 0 19.3K
EmbeddedWala Jun 14, 2023 0 19.2K
EmbeddedWala Apr 26, 2023 0 17.3K
EmbeddedWala Aug 30, 2022 0 15.3K
EmbeddedWala Apr 27, 2023 0 15.3K
EmbeddedWala Jun 19, 2022 0 4.5K
This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies Find out more here