Storage Classes Flashcards

1
Q

Usage of Storage Classes?

A

used to describe the features of variable or a function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Features of storage classes

A

the features basically includes:
1.Scope
2.Default initial value
3.lifetime..(refers to duration of variable)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

4 types of storage classes in c

A

1.Automatic
2.Extern
3.Static
4.Register.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Automatic storage classes

A

●Automatic variables are allocated memory automatically at runtime.
● The life of the automatic variables is limited to the block in which they are
defined.
● The scope of the automatic variables is limited to the block in which they
are defined.
● The automatic variables are initialized to garbage by default.
● The memory assigned to automatic variables gets freed upon exiting from
the block.
● The keyword used for defining automatic variables is auto.
● Every local variable is automatic in C by default.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Extern Storage class

A

● The external storage class is used to tell the compiler that the variable
defined as extern is declared with an external linkage elsewhere in the
program.
● The variables declared as extern are not allocated any memory. It is only
declaration and intended to specify that the variable is declared elsewhere
in the program.
● The default initial value of external integral type is 0 otherwise null.
● We can only initialize the extern variable globally, i.e., we can not initialize
the external variable within any block or method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Extern Storage class

A

● The external storage class is used to tell the compiler that the variable
defined as extern is declared with an external linkage elsewhere in the
program.
● The variables declared as extern are not allocated any memory. It is only
declaration and intended to specify that the variable is declared elsewhere
in the program.
● The default initial value of external integral type is 0 otherwise null.
● We can only initialize the extern variable globally, i.e., we can not initialize
the external variable within any block or method.
● An external variable can be declared many times but can be initialized only
once.
● If a variable is declared as external then the compiler searches for that
variable to be initialized somewhere in the program which may be extern
or static. If it is not, then the compiler will show an error.
● Their lifetime equals the lifetime of the program.
● They are not usually recommended.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Static storage class

A

● The variables defined as static specifier can hold their value between the
multiple function calls.
● Local Scope: Static local variables are available only to the function or the
block in which they are defined.
● Global Scope: Static global variables are available for the entire program.
● Default initial value of the static integral variable is 0 otherwise null.
● The keyword used to define static variable is static.
● They are not usually recommended.
● Their lifetime is throughout the program.
● Static variable can only be initialized with constant value, cannot assign
function value.
● A global static variable cannot be accessed outside the program, while a
global variable can be accessed by other source files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Register Storage Class

A

● The variables defined as the register is allocated the memory into the CPU
registers depending upon the size of the memory remaining in the CPU.
● Its scope is limited to the function it is defined in.
● Lifetime is till the end of the function block
● We can not dereference the register variables, i.e., we can not use &
operator for the register variable.
● The access time of the register variables is faster than the automatic
variables.
● The initial default value of the register local variables is 0.
● The register keyword is used for the variable which should be stored in the
CPU register.
● However, it is compiler’s choice whether or not; the variables can be stored
in the register.
● We can store pointers into the register, i.e., a register can store the address
of a variable.
● Static variables can not be stored into the register since we can not use
more than one storage specifier for the same variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Also read lecture 21 last slide

A

for sure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly