4 ms·
I was so surprised by the first question that I actually tried it on my computer... Am I the only one who tried compiling : #include<stdio.h> #include<stdlib.
by nspattak 12y ago
I was so surprised by the first question that I actually tried it on my computer...
Am I the only one who tried compiling :
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char *argv[])
{
int i;
int i=10;
printf("i=%d\n", i);
return 0;
}
and got the redeclaration error I expected?
- MikeTaylor 12y agoThe original article makes it clear that this is how things work with C globals, not locals. If you compile and run this program with gcc -Wall -pedantic x.c && ./a.out there will be no errors and it will emit i=10 as expected: int i; int i=10; #include<stdio.h> int main(int argc, char *argv[]) { printf("i=%d\n", i); return 0; }