![]() The conditional codes are included in the program only if the expression is evaluated to a non-zero value. Here, expression is an expression of integer type (can be integers, characters, arithmetic expression, macros, and so on). #if, #elif and #else Directive #if expression Here, the conditional codes are included in the program only if MACRO is defined. To use conditional, #ifdef, #if, #defined, #else and #elif directives are used. to exclude certain code from the program but to keep it as a reference for future purposes.compile the same source file in two different programs.use different code depending on the machine, operating system.The if statement is tested during the execution time to check whether a block of code should be executed or not whereas, the conditionals are used to include (or skip) a block of code in your program before execution. It's similar to a if statement with one major difference. To do so, conditional directives can be used. In C programming, you can instruct the preprocessor whether to include a block of code or not. ![]() Visit this page to learn more about macros and #define preprocessor. Suppose, we passed 5 as an argument then, it expands as below: circleArea(5) expands to (3.1415*5*5)Įxample 2: Using #define preprocessor #include For example, #define circleArea(r) (3.1415*(r)*(r))Įvery time the program encounters circleArea(argument), it is replaced by (3.1415*(argument)*(argument)). You can also define macros that work in a similar way as a function call. Here, when we use c in our program, it is replaced with 299792458.Įxample 1: #define preprocessor #include You can define a macro in C using the #define preprocessor directive. Visit this page to learn more about using header files.Ī macro is a fragment of code that is given a name. You can also create your own header file containing function declaration and include it in your program using this preprocessor directive. That's the reason why you need to use #include before you can use functions like scanf() and printf(). The #include preprocessor directive replaces the above line with the contents of stdio.h header file. The #include preprocessor is used to include header files to C programs. ![]() Some of the common uses of C preprocessors are: These transformations can be the inclusion of header files, macro expansions, etc.Īll preprocessing directives begin with a # symbol. The C preprocessor is a macro preprocessor (allows you to define macros) that transforms your program before it is compiled.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |