Storage Classes
Storage Classes
Properties of a variable: A variable in C language is associated with the
following properties: Property Meaning
Name : Name is used to refer to variable. This is a symbol using which the
value of the variable is accessed or modified. Data type Specifies what type of
value the variable can store
Value : The value that is stored in the variable. The value is not known unless
the variable is explicitly initialized.
Address :The address of the memory location where the variable is allocated
space
Scope :Specifies the region of the program from where variable can be
accessed.
Visibility : Specifies the area of the program where variable is visible. Extent
Specifies how long variable is allocated space in memory.
Blocks: C is a block structured language. Blocks are delimited by { and }. Every block
can have its own local variables. Blocks can be defined wherever a C statement
could be used. No semi-colon is required after the closing brace of a block.
Scope :
The area of the program from where a variable can be accessed is called as scope of
the variable. The scope of a variable determines over what parts of the program a
variable is actually available for use (active). Scope of the variable depends on where
the variable is declared.
int g; /* scope of g is from this point to end of program */
main()
{
int x; /* scope of x is throughout main function */
....}
void sum()
{ int y; /* scope of y is throughout function sum */
....}
mmain.c #include"write.c“
int count=5;
main()
{
write_extern();
write_extern();
variable.h /* program1 */
extern int num1 = 9;
extern int num2 = 1;
extern.c /* program2 */
#include <stdio.h>
#include "variable.h"
int main()
{
int add = num1 + num2;
printf("%d + %d = %d ", num1, num2, add);
return 0;
}
o/p:
9 + 1 = 10