Illustrating Static and Automatic Variables - C Function

C examples for Function:static

Description

Illustrating Static and Automatic Variables

Demo Code

#include <stdio.h>

void auto_static (void)
{
    int autoVar = 1;
    static int staticVar = 1;

    printf ("automatic = %i, static = %i\n", autoVar, staticVar);

    ++autoVar;/*from  w w  w  .j av  a 2s.  c  o m*/
    ++staticVar;
}

int main (void){
    for (int i = 0; i < 5; ++i)
        auto_static ();

    return 0;
}

Related Tutorials