Using a local static variable - C Function

C examples for Function:Local Variable

Description

Using a local static variable

Demo Code

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

int main(void){
    int count;/*w  w w . ja  v  a  2 s . c o  m*/
    
    for (count = 1; count <= 3; count++){
        printf("Here comes iteration %d:\n", count);
        trystat();
    }
    
    return 0;
}

void trystat(void)
{
    int fade = 1;
    static int stay = 1;
    
    printf("fade = %d and stay = %d\n", fade++, stay++);
}

Related Tutorials