Storage Classes in C: Static, Extern, Auto and register.
#include <stdio.h>
// int sum = 897;
// int sum = 0;
int myfunc(int a, int b)
{
// int sum;
static int myVar;
myVar ++;
printf("The myVar is %d\n", myVar);
// sum = a + b;
return myVar;
}
// int myVar = 898;
int main()
{
int myVar = myfunc(3, 5);
myVar = myfunc(3, 5);
myVar = myfunc(3, 5);
myVar = myfunc(3, 5);
myVar = myfunc(3, 5);
myVar = myfunc(3, 5);
return 0;
}
OUTPUT:
The myVar is 1
The myVar is 2
The myVar is 3
The myVar is 4
The myVar is 5
The myVar is 6
Crystal clear
ReplyDeleteThe way you write the code is awesome
ReplyDelete