Download Computer Science Useful Resources
Review targeted academic resources with the Problem Solving Through C Unit 07 Storage Classes Notes Set 01. Built according to official standards for the 2026-27 term, these downloadable Computer Science study materials support effective daily practice and deeper conceptual understanding for Programming in C.
Access Study Guides and Summaries
View or download the dedicated Problem Solving Through C Unit 07 Storage Classes Notes Set 01 resource below. Engaging with these advanced study guides under focused conditions ensures continuous academic progress and mastery of the 2026-27 curriculum for Programming in C.
This page explains the scope, extent and longevity of variables in C and the four storage classes: auto, extern, static and register. Worked examples show automatic, global and static variables, static functions, and how extern declarations are used across multiple source files.
Scope of a Variable
The scope of a variable determines over what part(s) of the program a variable is actually available for use(active).
Longevity: it refers to the period during which a variables retains a given value during execution of a program(alive).
Local (internal) variables: are those which are declared within a particular function.
Global (external) variables: are those which are declared outside any function.
Scope of a Declaration
Scope of a declaration is the region of C program text over which that declaration is active.
Top-level identifiers - Extends from declaration point to end of file.
Formal parameters in functions - Extends from declaration point to end of function body.
Block/function (local) identifiers - Extends from declaration point to end of block/function.
Extent
The extent of an object is the period of time that its storage is allocated.
An object is said to have static extent when it is allocated storage at or before the beginning of program execution and the storage remains allocated until program termination.
All functions have static extent, as do all variables declared in top-level declarations and variables declared with the static qualifier.
Formal parameters and variables declared at the beginning of a block or function have local extent (dynamic, de-allocated on block/function exit).
External variable or function
A top-level identifier is treated just like a static extent object in the file containing its definition, but is also exported to the linker, and if the same identifier is declared in another file, the linker will ensure the two files reference the same object (variable or function).
Thus, top-level identifiers and functions are external by default.
The convention is to use the extern qualifier in all places that are simply declaring an identifier that is defined (allocated) in another file, and to omit the qualifier at the single point where the variable is actually defined (allocated space).
Thus external is the same as "global" or "public".
A static variable or function: has only file scope, is not external.
Thus static is the same as "private."
Examples
Variables, top-level:
int x = 3; //defining, exported (external by default) - static extent
extern int w; //declaring, imported (variable is defined elsewhere)
static int y; //not exported/external (file scope) - static extent
Functions:
int f(int xx){ //exported (external by default) - static extent
int zz; //local (function scope) - local extent
...
}
static int g(int yy){ //not exported (file scope) - static extent
...
}Storage Classes
A storage class defines the scope (visibility) and life time of variables and/or functions within a C Program.
There are following storage classes which can be used in a C Program
Auto,
Extern,
Static,
Register.
Automatic variables
Are declared inside a function in which they are to be utilized.
Are declared using a keyword auto. e.g. auto int number;
Are created when the function is called and destroyed automatically when the function is exited.
These variables are therefore private (local) to the function in which they are declared.
Variables declared inside a function without storage class specification is, by default, an automatic variable.
Auto is the default storage class for all local variables.
{
int Count;
auto int Month;
}The example above defines two variables with the same storage class.
Auto can only be used within functions, i.e. local variables.
Example program
int main()
{
int m=1000;
function2();
printf("%d\n",m);
}
function1()
{
int m = 10;
printf("%d\n",m);
}
function2()
{
int m = 100;
function1();
printf("%d\n",m);
}
Output
10
100
1000About Auto Variables
Any variable local to main will normally live throughout the whole program, although it is active only in main.
During recursion, the nested variables are unique auto variables.
Automatic variables can also be defined within blocks.
In that case, they are meaningful only, inside the blocks where they are declared.
If automatic variables are not initialized - will contain garbage.
The features of automatic variables are
Storage - memory.
Default initial value - an unpredictable value, which is often a garbage value.
Scope - local to the block in which the variable is defined.
Life - till the control remains within the block variable is defined.
External Variables
These variables are declared outside any function.
These variables are active and alive throughout the entire program.
Also known as global variables and default value is zero.
Unlike local variables they can be accessed by any function in the program.
In case local variable and global variable have the same name, the local variable will have precedence over the global one.
Sometimes the keyword extern is used to declare these variables.
Extern is used to give a reference of a global variable that is visible to all the program files.
It is visible only from the point of declaration to the end of the program.
The extern variable cannot be initialized, as all it does is, point the variable name at a storage location that has been previously defined.
When a programmer has multiple files and he defines a global variable or function, which will be used in other files also, then extern will be used in another file to give reference of defined variable or function.
Extern is used to declare a global variable or function in another file.
External Declaration
int main()
{
y=5;
...
}
int y;
func1()
{
y=y+1;
}As far as main is concerned, y is not defined.
So compiler will issue an error message.
There are two way out at this point
Define y before main.
Declare y with the storage class extern in main before using it.
External Declaration(Examples)
int main()
{
extern int y;
...
}
func1()
{
extern int y;
...
}
int y;Note that extern declaration does not allocate storage space for variables.
External Variable (Examples)
extern int a=1, b=2;
External variable never disappear.
Because exist throughout the execution life of the program, they can be used to transmit value across functions.
They may be, hidden if the identifier is redefined.
All functions have external storage class.
This means that the keyword extern can be used in function definitions and in function prototypes.
For example;
extern double sin(double);
In a function prototype, for the sin() function; its function definition - we can write;
extern double sin(double)
{
------
------
}An extern within a function provides the type of information just to that one function.
The extern declaration does not allocate storage space for variables.
The features of external storage class variable are as follows:
Storage - memory.
Default initial value - zero.
Scope - global.
Life - as long as the program execution does not end.
Example
File 1: main.c
int count=5;
main()
{
write_extern();
}
File 2: write.c
void write_extern(void);
extern int count;
{
printf("count is %i\n", count);
}Here extern keyword is being used to declare count in another file.
Now compile these two files.
This file produces the write program which can be executed to produce result.
Count in 'main.c' will have a value of 5. If main.c changes the value of count - write.c will see the new value.
When the function references the variable count, it will be referencing only its local variable, not the global one.
Global Variable Example
int x;
int main()
{
x=10;
printf("x=%d\n",x);
printf("x=%d\n",fun1());
printf("x=%d\n",fun2());
printf("x=%d\n",fun3());
}
int fun1()
{
x=x+10;
return(x);
}
int fun2()
{
int x;
x=1;
return(x);
}
int fun3()
{
x=x+10;
return(x);
}
Output
x=10
x=20
x=1
x=30Once a variable has been declared global any function can use it and change its value.
The subsequent functions can then reference only that new value.
Static Variables
The value of static variables persists until the end of the program.
It is declared using the keyword static like
static int x; static float y;
It may be of external or internal type depending on the place of the declaration.
Static variables are initialized only once, when the program is compiled.
Static is the default storage class for global variables.
The two variables below (count and road) both have a static storage class.
static int Count;
int Road;
{
printf("%d\n",Road);
}Static variables can be 'seen' within all functions in this source file.
At link time, the static variables defined here will not be seen by the object modules that are brought in.
Static can also be defined within a function.
If this is done, the variable is initialized at run time, but is not reinitialized, when the function is called.
Inside a function, static variable retains its value during various calls.
Example
static int Count;
int Road;
{
printf("%d\n",Road);
}
void func(void);
static count=10; /* Global variable - static is the default */
main()
{
while (count--)
{
func();
}
}
void func( void )
{
static int i = 5;
i++;
printf("i is %d and count is %d\n", i, count);
}This will produce following result
i is 6 and count is 9 i is 7 and count is 8 i is 8 and count is 7 i is 9 and count is 6 i is 10 and count is 5 i is 11 and count is 4 i is 12 and count is 3 i is 13 and count is 2 i is 14 and count is 1 i is 15 and count is 0
NOTE: Here keyword 'void' means function does not return anything and it does not take any parameter.
Static Function
Static declaration can also be used to control the scope of a function.
If one wants a particular function to be accessible only to the functions in the file in which it is defined and not to any function in other files, declare the function to be static. e.g.
static int power(int x, int y)
{
...
...
}Internal Static Variable
Are those which are declared inside a function?
Scope of Internal static variables extends up to the end of the program in which they are defined.
Internal static variables are almost same as auto variable except they remain in existence (alive) throughout the remainder of the program.
Internal static variables can be used to retain values between function calls.
Examples (Internal Static)
Internal static variable can be used to count the number of calls made to function. e.g.
int main()
{
int i;
for (i=1; i<=3; i++)
stat();
}
void stat()
{
static int x=0;
x = x+1;
printf("x = %d\n",x);
}
Output
x=1
x=2
x=3External Static Variables
An external static variable is declared outside of all functions and is available to all the functions in the program.
An external static variable seems similar simple external variable but their difference is that static external variable is available only within the file where it is defined while simple external variable can be accessed by other files.
Register Variable
These variables are stored in one of the machine's register instead of RAM and are declared using register keyword.
E.g. register int count;
This means that the variable has a maximum size equal to the register size (usually one word) and cannot have the unary '&' operator applied to it (as it does not have a memory location).
{
register int Miles;
}Since register access are much faster than a memory access keeping frequently accessed variables in the register lead to faster execution of program.
Register should only be used for variables that require quick access - such as counters.
It should also be noted that defining 'register' does not mean that the variable will be stored in a register.
It means that it MIGHT be stored in a register - depending on hardware and implementation restrictions.
Since only few variables can be placed in the register, it is important to carefully select the variables for this purpose.
However, C will automatically convert register variables into non-register variables once the limit is reached.
Don't try to declare a global variable as register. Because the register will be occupied during the lifetime of the program.
Multifile Programs and Extern Variables
file1.c
int main()
{
extern int m;
int i;
...
...
}
function1()
{
int j;
...
...
}
File2.c
int m;
function2()
{
int i;
...
...
}
function3()
{
int count;
...
...
}Multi Files - Static Variables
Example
File1.c
static int i = 10;
void main()
{
/* i is accessible */
}
void function()
{
/* i is accessible */
}
File2.c
void function2()
{
/* static i of file1.c is not accessible here */
}
void function2 ()
{
/* static i of file1.c is not accessible here */
}Free study material for Computer Science
CBSE Computer Science Study Material: Programming in C
Quick Revision Material for Programming in C
Review targeted study resources for Programming in C tailored for learners. Utilizing these structured notes and quick-revision tools ensures complete alignment with current CBSE evaluation standards.
Expert Notes and Solved Exam Questions
Designed around the official curriculum, these study guides guarantee standard compliance. Reviewing step-by-step solutions clarifies complex sub-topics within Programming in C and demystifies standard marking schemes for Computer Science evaluations.
Additional Study Resources for
For peak performance in upcoming evaluations, integrate official Computer Science sample papers directly into your study schedule. Follow up your revision by attempting online MCQ tests for Programming in C to refine calculation speed and precision.
FAQs
The latest 2026-27 advanced study resources for Computer Science are available for free on StudiesToday.com which includes NCERT Exemplars, high-order thinking skills (HOTS) questions, and deep-dive concept summaries.
Our exhaustive Computer Science package includes chapter wise revision notes, solved practice sheets, important formulas and Concept Maps to help in better understanding of all topics.
Yes. For , our resources have been developed to help you get better marks in school exams and also build fundamental strength needed for entrance tests including Competency Based learning.
in , students should use Active Recall method, read the concept summary, then solve the Important Questions section without looking at the answers and then check your answers.
All Computer Science study materials are provided in mobile-friendly PDF. You can download and save them on your device.
Yes, our team has ensured that all Computer Science materials for are strictly aligned with the National Education Policy (NEP) 2020 and the latest 2026-27 syllabus.