In C, is it valid to declare a variable multiple times? -


i have below c code , expecting throw error "multiple declaration of variable", not doing so.

#include <stdio.h>  int i;         int i;      int main() {     printf("%d",i);     return 0; } 

now output 0, why?

and 1 more thing below code gives error expected

#include <stdio.h>   int main() {     int i;             int i;          printf("%d",i);     return 0; } 

o/p error saying re declaration of i

the first definition of i tentative definition (the 2nd tentative definition). "de facto" definitions though (and definitions serve declarations), no mistake it.

quote the standard:

6.9.2/2

a declaration of identifier object has file scope without initializer, , without storage-class specifier or storage-class specifier static, constitutes tentative definition. if translation unit contains 1 or more tentative definitions identifier, , translation unit contains no external definition identifier, behavior if translation unit contains file scope declaration of identifier, composite type of end of translation unit, initializer equal 0.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -