Professional Documents
Culture Documents
Macros and Storage Classes
Macros and Storage Classes
The Preprocessor : Preprocessor is program which processes our source code before passing it to the compiler. The statement which begins with a # symbol is called as preprocessor directive. There are 2 types of preprocessor directives They are : 1) #include directive 2) #define directive Note : - preprocessor directives are not C language instructions. They are replaced by appropriate C code.
Macros : A Macro is a constant defined by using the preprocessor directive # define. Macros are 2 types 1. Simple Macros 2. Macros with arguments Defining a macro : Syntax : #define <Macro Name><Macro expansion> Ex: #define NULL 0
There are several uses of macros : Increase program readability Performs automatic replacement Reduces Typing Burden Increases program execution speed Macros with arguments : Macros can have arguments just like a function.
Storage Classes
In C there are 4 types of storage classes 1. auto (automatic) 2. static 3. register (CPU register) 4. extern (external)
The Storage class tells us four things : 1) Default initial value : what will be the default initial value of the variable as soon as it is defined. 2) Location : where the variable would be stored. 3) Scope : where the variable can be accessed. 4) Life : How long the memory remains reserved for the variable.
auto
static
register
Extern
Garbage
0 (ZERO)
Garbage
0 (ZERO)
RAM
RAM
CPU registers
RAM
Scope
Local to the block where the variable is defined As long as the control is with in the block where the variable is defined
Local to the block where the variable is defined As long as the program is under execution
Local to the block where the variable is defined As long as the control is with in the block where the variable is defined
Entire Program
Life