How to change (access to an element) an array element through a pointer to it?
var q: array of integer; Pq: pointer; begin pq:=addr(q); end;
How to change (access to an element) an array element through a pointer to it?
var q: array of integer; Pq: pointer; begin pq:=addr(q); end;
Well, probably so. Maybe there is a better way, but I had to do this a couple of times. In C and C ++ with pointers to arrays (and to elements) everything is much simpler and more interesting. In my opinion, it is better not to use pointers if you can do without them.
program Project1; {$APPTYPE CONSOLE} uses SysUtils; Var Mas: Array[0..99] Of Integer; PMas: ^Integer; i, n: Byte; begin Write(' n = '); ReadLn(n); Randomize; For i:=0 To N-1 Do Begin // PMas:=Addr(Mas[i]); можно написать так PMas:= @Mas [i]; PMas^:=Random(100)-Random(100); WriteLn(' ', PMas^); End; ReadLn; end.
Source: https://ru.stackoverflow.com/questions/57227/
All Articles