I have a code like this:
#include<stdio.h>
int main()
{
extern int i;
i = 20;
printf("%d\n", sizeof(i));
return 0;
}
I get an error like this:
In function `main':
undefined reference to `i'
Even though I have defined i why there is an error thrown?
Thanks in advance.
You have declared i to be defined in a separate file, but haven’t linked to an external file.
If you remove the extern keyword, this will work as you expect.