c program to show automatic variable scope

Automatic variable scope :

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. An Automatic variable is a default scope in which a variable  is allocated and freed automatically when program flow enters and leaves the variable’s scope. The automatic variable in c is same as automatic variable referred in other programming languages.
The scope of automatic variable defined within a function is limited to the function block and the scope of automatic variable defined in main ends with program. The Keyword ‘auto’  is used  to define automatic variable.
By default if no scope is defined for a variable then it is treated as automatic variable. so, it is optional to declare ‘auto’ for automatic scope variables.

c program to show automatic variable scope
c program to show automatic variable scope

write a c program to show automatic variable scope

write a c program for showing automatic variable scope

#include<stdio.h>
void fun()
{
int n=30;
printf(“\n  Inside Function”);
printf(” \n n= %d”,n);
}

int main()
{
int n=5;
printf(” The Value of automatic variable before calling Function”);
printf(“\n n= %d”,n);
fun();
printf(“The Value of Automatic variable after calling Function”);
printf(“\n n= %d”,n);
}

OUTPUT:

The Value of Automatic variable before calling Function
5

Inside Function
The Value of Automatic variable after calling Function
30

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 *