- UNIT-I (Array)
strlen(),strcpy(),strcat() ,strcmp()
Definition
Macro substitution directives
File inclusion directives
Conditional compilation
Bitwise Operators
Shift operators
Masks
Bitfield
Macro substitution directives
File inclusion directives
Conditional compilation
Bitwise Operators
Shift operators
Masks
Bitfield
Macro substitution directives
Macro substitution has a name and replacement text, defined with #define directive. The preprocessor simply replaces the name of macro with replacement text from the place where the macro is defined in the source code.
Simple Macro Substitution Directive in c:
syntax:
#define identifier value
Example:
#define VALUE 10 //capital identifier name
D=VALUE-5;
Answer is 3
Simple Macro Substitution Directive in c:
syntax:
#define identifier value
Example:
#define VALUE 10 //capital identifier name
D=VALUE-5;
Answer is 3
A macro is a segment of code which is replaced by the value of macro. Macro is defined by #define directive. There are two types of macros:
- Object-like Macros
- Function-like Macros
Object-like Macros
The object-like macro is an identifier that is replaced by value. It is widely used to represent numeric constants. For example:
#define PI 3.14
Here, PI is the macro name which will be replaced by the value 3.14.
Function-like Macros
The function-like macro looks like function call. For example
#define MIN(a,b) ((a)<(b)?(a):(b))
C Predefined Macros
ANSI C defines many predefined macros that can be used in c program.
No. | Macro | Description |
---|---|---|
1 | _DATE_ | represents current date in "MMM DD YYYY" format. |
2 | _TIME_ | represents current time in "HH:MM:SS" format. |
3 | _FILE_ | represents current file name. |
4 | _LINE_ | represents current line number. |
5 | _STDC_ | It is defined as 1 when compiler complies with the ANSI standard. |
C predefined macros example
File: simple.c
Output:
File :simple.c Date :Dec 6 2015 Time :12:28:46 Line :6 STDC :1
कोई टिप्पणी नहीं:
एक टिप्पणी भेजें