0% found this document useful (0 votes)
31 views11 pages

Chapter 5: Function: Storage Class

Storage classes determine the scope and lifetime of variables. There are four storage classes: auto, register, static, and extern. Auto variables are local to a function and destroyed when the function ends. Register variables are stored in CPU registers for quick access but limited in size. Static variables persist between function calls and are stored in memory. Extern variables can be accessed from any function and are stored in memory.

Uploaded by

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

Chapter 5: Function: Storage Class

Storage classes determine the scope and lifetime of variables. There are four storage classes: auto, register, static, and extern. Auto variables are local to a function and destroyed when the function ends. Register variables are stored in CPU registers for quick access but limited in size. Static variables persist between function calls and are stored in memory. Extern variables can be accessed from any function and are stored in memory.

Uploaded by

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

Chapter 5: Function

Storage Class
• Storage classes are used to determine the
scope and lifetime of a variable.
• In computer, two types of storage are
available
– Memory
– CPU Registers
• Four types of storage classes:
– Auto
– Register
– Static
– Extern
Auto Storage Class
• Auto is the default storage class for local variable
• For example:
void abc()
{
int a;
auto int b;
}
• Here b is local variable to abc() .
• Auto variables are created when the function is
called and destroy automatically when function finish
its execution.
• Features:
– Storage: Memory
– Scope: local to the function or block in which it is
defined
– Life: Till the control remains within a function.
– Default Value: Garbage Value
Register Storage Class
• Default storage class for local variable.
• It is stored in a CPU register instead of memory.
• Maximum size for storage is equal to register size.
• Generally used for variables which required quick
access
• For example: count++
• Features:
– Storage: CPU Register
– Scope: local to the function or block in which it is
defined
– Life: Till the control remains within a function.
– Default Value: Garbage Value
Static Storage class
• Default storage class for global variables
• For example:
#include<stdio.h>
static int a;
int b;
void main()
{
printf(“a=%d \n b= %d”,a,b);
}
• Static can also be defined as a local variables
• Features:
– Storage: Memory
– Scope: local or global
– Life: Persist between different function calls
– Default Value: zero
Extern Storage Class
• Default storage class for global variables and
can be access by any functions
• Declared outside functions
• For example:
int a=0;
extern int b;
void main()
{
extern int c;
int d;
• Features:
– Storage: Memory
– Scope: Global
– Life: Throughout the program
– Default Value: zero

You might also like