Deklarieren von Variablen ohne Datentyp in c

In diesemc Programm

a=8;
main()
{
    printf("%d", a);
}   

Die Variable a wurde ohne Datentyp deklariert und trotzdem kompiliert dieses Programm erfolgreich und gibt die gewünschte Ausgabe aus.
Ausgabe ::

8  

sieh es anideone.
aber wenn ich die gleiche Variable in main deklariert habe, gibt es einen Kompilierungsfehler.

main()
{
     a=8;
    printf("%d", a);
}  

Ausgabe ::

prog.c:2: warning: return type defaults to ‘int’
prog.c: In function ‘main’:
prog.c:3: error: ‘a’ undeclared (first use in this function)
prog.c:3: error: (Each undeclared identifier is reported only once
prog.c:3: error: for each function it appears in.)
prog.c:4: warning: implicit declaration of function ‘printf’
prog.c:4: warning: incompatible implicit declaration of built-in function ‘printf’  

sehenHier.

Wie funktioniert das erste Programm, aber das zweite?

Antworten auf die Frage(6)

Ihre Antwort auf die Frage