here is my piece of code
#include<stdio.h>
main ()
{
extern int i;
i=20;
printf("%d",i);
}
When I compile it I get error
ka2.c: In function ‘main’:
ka2.c:6: warning: format ‘%d’ expects type ‘int’, but 开发者_运维问答argument 2 has type ‘long unsigned int’
/tmp/ccGXrSE5.o: In function `main':
**ka2.c:(.text+0x6): undefined reference to `i'**
collect2: ld returned 1 exit status
I want to know the reason of error in lines which I have bolded.
You have declared i
but haven't defined it, that's why the linker is complaining.
You declared i as extern. Removing this keyword fixes the issue, because extern means something which is defined in another module
精彩评论