Now, from what I understand, extern in the name[] declaration tells the compiler that its definition is somewhere else (in my program, I defined it below the part where I used it). But why then there are different consequences for strlen() and sizeof ? strlen() works fine, but for sizeof() I get an error:
invalid application of 'sizeof' to incomplete type 'char[]' |
Here is my program:
#include<stdio.h> #include<string.h> extern char name[]; int main() { printf("%d,%d",strlen(name),sizeof(name)); } char name[]="Bryan"; //char name[6]="Bryan"; //Neither of these make sizeof work
I tried to explain this based on my understanding of the extern keyword, but I got into a bottleneck. So please give your answers.
source share