F_GXdx
Captain
- Registriert
- März 2006
- Beiträge
- 4.028
Hallo,
Laut Wikipedia ist
int x;
eine Deklaration und Definition.
Für Subroutinen ist
int funktion(int x);
eine Deklaration aber keine Definition. Erst wenn die Funktion einen Inhalt bekommt, ist es auch eine Definition: (Obiges Beispiel wäre also ein Prototyp, wie man auch sagt)
zB
int funktion(int x){
x++;
return x;
}
Irgendwie finde ich das unlogisch, weil sich dabei 2 Widersprüche auftun:
1) Bei der Subroutine wird SPEICHERPLATZ und NAME festgelegt, mehr wird bei int x; ja auch nicht festgelegt, SPEICHERPLATZ und NAME. Warum ist dann das eine eine Definition und das andere nicht?
2) Nach dieser Logik wäre ja auch erst int x = 5; eine Definition und int x; nur eine Deklaration.
Was stimmt jetzt?
Danke und Gruß,
Tobias
Laut Wikipedia ist
int x;
eine Deklaration und Definition.
Für Subroutinen ist
int funktion(int x);
eine Deklaration aber keine Definition. Erst wenn die Funktion einen Inhalt bekommt, ist es auch eine Definition: (Obiges Beispiel wäre also ein Prototyp, wie man auch sagt)
zB
int funktion(int x){
x++;
return x;
}
Irgendwie finde ich das unlogisch, weil sich dabei 2 Widersprüche auftun:
1) Bei der Subroutine wird SPEICHERPLATZ und NAME festgelegt, mehr wird bei int x; ja auch nicht festgelegt, SPEICHERPLATZ und NAME. Warum ist dann das eine eine Definition und das andere nicht?
2) Nach dieser Logik wäre ja auch erst int x = 5; eine Definition und int x; nur eine Deklaration.
Was stimmt jetzt?
Danke und Gruß,
Tobias
Zuletzt bearbeitet: