Monday 6 May 2019

c - Static vs global



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




#include 
#include

static int i;
int j;

int main ()
{
//Some implementation

}

Answer



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.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...