extern, static variables, enum, register

Static variable
When static storage class is given, it is initialized once. The change in the value of a static variable is retained even between the function calls. Main is also treated like any other ordinary function, which can be called recursively.

extern storage class in the following declaration,
extern int i;
specifies to the compiler that the memory for i is allocated in some other program and that address will be given to the current program at the time of linking. But if the linker finds that no other variable of name i is available in any other program with memory space allocated for it. It will generate linker error.

enum colors {BLACK,WHITE,GREEN}
By default enum assigns numbers starting from 0, if not explicitly defined. So BLACK = 0 ,WHITE=1, GREEN=2
Enumerated constants can be used in switch cases also. i.e. ‘case BLACK:’ is allowed.
Enumerated constants cannot be modified, so you cannot apply ++GREEN …

Global Variable
Even though a variable is declared as a global variable, it is visible in the code that follows the declaration only. So if it occurs in the code before its declaration, it will cause compilation error.
main(){
printf(“%d”, out);
}
int out=100;
This will raise error. while,

main(){
printf(“%d”, out);
}
extern out=100;
will work fine.

global declared variables are automatically initialized to zero, where as local variables are initialized to junk.

register variable
If you declare i as register

Leave a Reply

Your email address will not be published. Required fields are marked *