c program to show static variable scope

Static variable scope in c language:

To write  a c program to show static variable scope lets know what is an static variable.

There are four types of storage classes or variable scopes seen in c programming language which are Automatic variable scope, register variable scope, Static variable scope and external variable scope.

Local variables are automatic by default. This means that local variables are created as new each time the function is called, and they are destroyed when execution leaves the function. What this means, in practical terms, is that an automatic variable doesn’t retain its value between calls to the function in which it is defined.In order for a local variable to retain its value between calls, it must be defined as static with the static keyword.

c program to show static variable scope
c program to show static variable scope

write a C program to show static variable scope

write a C program to show static variable scope

#include <stdio.h>
void add(void);
int main()
int i,n=5;
printf(“\n static storage example \n”);
for(i = 0; i<5; i++)
void add(void)
static int sum = 0;
int num;
printf(“\nEnter a number: “);
scanf(“%d”, &num);
sum += num;
printf(“\n The current total is: %d\n”, sum);

Other Related Programs

external variable scope
register variable scope
automatic variable scope


Other programs:

Static variable scope
Register variable scope
External variable scope
Automatic variable scope
amicable number
Prime number
Perfect number
Palindrome number
Strong number
Find Factorial 
Biggest Number
Average of n numbers
convert decimal number to octal
decimal number to hexadecimal
decimal number to binary
simple interest
compound interest
Add sparce matrices
Add matrices
 file copying
Palindrome string
Reverse string
String length
Replace characters in string
substring or not using arrays
First occurrence of character in string
Last occurrence of character in string
Convert to uppercase
Convert to lowercase
Concatenate strings 
Compare strings
Generate Employee payslips
Count students scoring marks>50%
convert weight into grams


Leave a Reply

Your email address will not be published. Required fields are marked *