0% found this document useful (0 votes)
13 views2 pages

CPR Experiment 6

.

Uploaded by

backupwashere839
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

CPR Experiment 6

.

Uploaded by

backupwashere839
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

CPR Experiment 6:

Aim: Program to demonstrate Storage Classes –Auto, Extern, Static, Register

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:

Write the output of following codes and justify the answer.

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 : __________________

Practical Relation Theory Questions:


1. Write the use of register and extern storage classes.

You might also like