Write a C program to declare a local variable using the auto storage class and display its value.
Write a C program to declare a local variable using the
auto storage class and display its value.
The auto storage class is the default storage class for
local variables. An automatic variable exists while the block in
which it is declared is executing.
Value = 25
Write a C program to demonstrate the use of a local auto
variable inside a function.
The auto variable is local to the function. Its scope is
limited to that function block.
Value inside function = 10
Write a C program to demonstrate a register variable
used as a loop counter.
The register storage class is used to request that a
frequently accessed local variable be kept in a CPU register when
practical. The compiler decides whether the request can be honored.
1 2 3 4 5
Write a C program using a static local variable to
demonstrate that its value is preserved between function calls.
A local static variable retains its value between
function calls. Unlike an ordinary local variable, it is not
reinitialized on every call.
Count = 1
Count = 2
Count = 3
Write a C program to compare an ordinary local variable with a static local variable by calling the same function three times.
The ordinary local variable is initialized again on every function call, so its value remains 1. The static variable retains its previous value and therefore increases with every call.
Normal = 1, Static = 1
Normal = 1, Static = 2
Normal = 1, Static = 3
Write a C program to demonstrate an extern variable
declared outside the function and accessed inside main().
The extern declaration tells the compiler that the
variable is defined elsewhere. Here, the actual definition of
number is outside main().
Number = 50
Write a C program to use a global variable with an extern
declaration inside a function and modify its value.
The extern declaration allows the function to refer to
the global variable defined outside it. Therefore, the update is
visible in main().
Before update = 20
After update = 30
Write a C program to demonstrate a static variable used to count how many times a function has been called.
The static variable retains its value after the function returns. This makes it useful for maintaining state across multiple calls.
Function called 1 time(s).
Function called 2 time(s).
Function called 3 time(s).
Function called 4 time(s).
Write a C program to demonstrate the difference between a normal local variable and a static local variable using repeated function calls.
The normal variable starts again from 10 on every function call. The static variable remembers its previous value and continues from where the previous call ended.
Normal = 15, Static = 15
Normal = 15, Static = 20
Normal = 15, Static = 25
Write a C program that demonstrates the use of auto,
register, static and extern
storage class concepts in one program.
This program demonstrates the basic behavior of four storage-class concepts. The automatic variable is recreated on each function call, the register variable is a local variable requested for register storage, the static variable retains its value, and the extern declaration refers to a variable defined elsewhere in the program.
Extern = 100
Auto = 10
Register = 20
Static = 1
Auto = 10
Register = 20
Static = 2