Write any C program to show the working of auto variable and static variable

 TASK-

Write any C program to show the working of auto variable and static variable.

SOMETHING ABOUT AUTO AND STATIC VARIABLES:

The main difference between auto and static variables is, the auto variable of a function doesn't store data while in static variable data is stored. In the case of the auto variable, the memory of the variable vanishes once the task is completed while in static variable value remains in variable till the program ends.

CODE:

#include<stdio.h>
void aut_stat();


int main(){
int y;


printf("Lets see the working of auto and static variable");


for (y=0;y<=3;y++)
aut_stat();
getchar();
return 0;
}


void aut_stat()
{
static int m=0;
int n=0;
printf("\n\nAuto = %d        static = %d",n,m);
    m++; //the value of m wouldn't be vanished when task of function ends
    n++;
}

EXPECTED OUTPUT:



NEED WORK PRODUCE WORK

My name is Abdul Rehman I am from Pakistan. I am doing BS in Computer and information sciences. Currently, I am creating these blogs to help students of computer sciences all over the world..

Post a Comment (0)
Previous Post Next Post