CPR Experiment 6
CPR Experiment 6
Theory:
Storage classes in C are used to define the scope, visibility, lifetime, and initial value of
variables and functions. Each storage class has its own unique properties and use cases.
1. Auto: Used for temporary variables that are good for short calculations. These
variables are stored in memory, and their scope is within the function. Auto is a
default storage class.
2. Register: Optimizes performance by storing data in CPU registers. The purpose of
this is to improve performance by making access to the variable faster.
3. Static: Retains the values of variables between function calls. It initializes the
variable only once in the lifetime of function.
4. Extern: Also known as global variables, these variables are available to all functions
in the program.
Exercise:
1. 2.
#include <stdio.h> #include <stdio.h>
void main() void main()
{ {
int k; int k;
void change(); void change();
for(k=1;k<=5;k++) for(k=1;k<=5;k++)
{ {
change(); change();
} }
} }
void change() void change()
{ {
auto int i=10; static int i=10;
printf("%d ",i); printf("%d ",i);
i = i +10; i = i +10;
} }
1) Output : 10 10 10 2) Output : 10 20 30
Reason :__________________ Reason : __________________