Example: #define symbol replacement
When the preprocessor encounters #define directive, it replaces any occurrence of symbol in the rest of the code by replacement. This replacement can be an statement or expression or a block or simple text.
Example: #define PI 3.14
We can undefine PI macro by #undef PI
Example: #define CUBE(X)(X*X*X)
#ifndef XSTRING_H
#define XSTRING_H defines the same preprocessor symbol,
Finally, the last line of the file, #endif
#include<stdio.h> #define INFINITELOOP while(1) int main() { INFINITELOOP printf("CuriousTab"); return 0; }
The macro INFINITELOOP while(1) replaces the text 'INFINITELOOP' by 'while(1)'
In the main function, while(1) satisfies the while condition and it prints "CuriousTab". Then it comes to while(1) and the loop runs infinitely.
Comments
There are no comments.Copyright ©CuriousTab. All rights reserved.