C - Writing extern keyword explicitly for global variable

Viewed 914

I have 2 C files below. From what i read i know that global variables' default storage class is extern. If i type it explicitly i am getting undefined variable error. What am i missing here? Does that mean when i omit extern keyword it becomes a definition but when i type it out its only a declaration?

file1.c

#include <stdio.h>
#include <stdlib.h>
extern void file2function();

int variable; // if i put extern i will get error, isnt it implicitly extern?

int main()
{
    variable = 1;
    printf("file1 %d\n",variable);
    file2function();
    return 0;
}

file2.c

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

extern int variable;


void file2function(){
    variable = 2;
    printf("file2 %d\n",variable);
    return;
}
1 Answers
Related