Static vs global

Vijay picture Vijay · Feb 16, 2010 · Viewed 47.2k times · Source

If I have a C file like below, what is the difference between i and j?

#include <stdio.h>
#include <stdlib.h>

static int i;
int j;

int main ()
{
    //Some implementation
}

Answer

CB Bailey picture CB Bailey · Feb 16, 2010

i has internal linkage so you can't use the name i in other source files (strictly translation units) to refer to the same object.

j has external linkage so you can use j to refer to this object if you declare it extern in another translation unit.