Static Variables in C.

 #include <stdio.h>

int b = 34;
// this is a global variable since it is declared outside the main
int func1(int b1)
{
    static int myvar  = 98;
    printf("The value of myvar is %d\n", myvar);
    myvar++;
    printf("The value of inside func1 is %d\n", b);
    printf("The address of inside func1 is %d\n", &b);
    return b1 + myvar;
}
int main()
{
    int b1 = 344;
     printf("The address of inside main is %d\n", &b);
    int val = func1(b);
    val = func1(b);
    val = func1(b);
    val = func1(b);
    val = func1(b);
    val = func1(b);
    int *ptr = &val;
    printf("The value of func1 is %d\n", val);
    return 0;
}
OUTPUT:
The address of inside func1 is 4210692 The value of myvar is 102 The value of inside func1 is 34 The address of inside func1 is 4210692 The value of myvar is 103 The value of inside func1 is 34 The address of inside func1 is 4210692 The value of func1 is 138

Comments

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.