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

Comments

Post a Comment

Popular posts from this blog

C Program using continue statement

C program of WHILE Loop

NULL Pointer in C.

C Program using DO WHILE loop

C Program using SWITCH statement

New Animated Login or signup page made by HTML, CSS and JavaScript.

C Program to print multiplication table of any number.

C Language Travel Agency Manager Exercise.

STRUCTURE IN C PROGRAMMING.