Autor Beitrag
kkkiwi
Hält's aus hier
Beiträge: 6



BeitragVerfasst: So 24.04.05 22:29 
hallo ihr

--> warum wird hier 22 ausgeben

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
  var zahl: integer;
procedure p(var z: integer);
begin
Zahl:= 11;
z:=z+z;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
zahl:=10;
p(zahl);
canvas.TextOut(100,100, inttostr(zahl));
end;

end.


schon mal danke

Moderiert von user profile iconMotzi: Delphi-Tags hinzugefügt und überflüssige Absätze entfernt.
Blackheart
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

ME
D3Prof.-D6Standard
BeitragVerfasst: So 24.04.05 22:38 
Weil Zahl 11 Ist und 11+11=22 Ist !
kkkiwi Threadstarter
Hält's aus hier
Beiträge: 6



BeitragVerfasst: So 24.04.05 22:46 
aber wo wird z zahl zugeordnet,
oder bdeutet das var z, das z zahl zugeordnet wird?
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8535
Erhaltene Danke: 473

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: So 24.04.05 22:49 
Habe mal in den Code n paar Kommentare reingetan...

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
var zahl: integer;
procedure p(var z: integer);
begin
//Schritt 3: Übergabe des Parameters per Referenz. d.h.: Zahl und z stehen an identischen Stellen im Speicher
//Schritt 4: Globale Variable Zahl erhöhen. Da diese der übergebene Parameter ist, ist dadurch auch z=11
Zahl:= 11;
//Schritt 5: z verdoppeln. Damit verdoppelt sich auch Zahl
z:=z+z;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
//Schritt 1: globale Variable Zahl auf 10 setzen
zahl:=10;
//Schritt 2: Prozedure p wird mit parameter zahl aufgerufen
p(zahl);
Schritt 6: gebe Zahl aus -> 22
canvas.TextOut(100,100, inttostr(zahl));
end;
end.

_________________
We are, we were and will not be.
kkkiwi Threadstarter
Hält's aus hier
Beiträge: 6



BeitragVerfasst: So 24.04.05 22:54 
danke :)