Thursday, July 9, 2009

Why do we use the symbol '#' before writing include<.......> in any C Program?

# indicates a preprocessor statement.





include is a preprocessor statement. So you need to put a # at the beginning of the line.

Why do we use the symbol '#' before writing include%26lt;.......%26gt; in any C Program?
this signals the compiler that the line is a preprocessing directive, which means that before the compiler actually process the code in the main() function it must first process the pre-process directives.





another preprocessing directive is the #define directive


which is declared right after the include directive





#include


#define





which is useful in declaring constant variables for example you need a variable that will hold the value of the constant pi, since pi is a constant value, it can't be changed since it's declared in the define directive





here's how it's declared





#define (name) (value)





it also works for "shorthand" code for those lazy enough to type the function name





#define p printf





instead of typing the whole printf to display text you simply type p followed by the parameters
Reply:C programs are preprocessed a Pre-Processor for macro expansion before they are passed onto the compiler. '#' character is sort of escape character for the pre-compiler. A variant of m4 macro expansion language is used by 'C' and 'C++' for macro processing. Hence all directives that start with '#' are processed by the pre-processor, for example, #define, #include, #if, #pragma etc.

marigold

No comments:

Post a Comment