Easy Tutorial
❮ C Function Isdigit C Intro ❯

C Exercise Example 41 - Static

C Language Classic 100 Examples

Title: Learn the usage of static variables defined with static.

Program Analysis: None.

Example

//  Created by www.tutorialpro.org on 15/11/9.
//  Copyright © 2015 tutorialpro.org. All rights reserved.
//

#include<stdio.h>
int main()
{
    void fun();
    for(int i=0;i&lt;3;i++)
        fun();
    return 0;
}
void fun()
{
    int i=0;
    static int static_i=0;
    printf("i=%d\n",i);
    printf("static_i=%d\n",static_i);
    i++;
    static_i++;
}

The output of the above example is:

i=0
static_i=0
i=0
static_i=1
i=0
static_i=2

C Language Classic 100 Examples

❮ C Function Isdigit C Intro ❯