This is my program:
program str_err;
var st:string;
begin
st:='ERROR';
delete(st,2,1);
writeln(st);
write(st[5]);
readln;
end.
I run it and it shows that st='EROR' and st[5]='R'?
I ‘ve already deleted one character from the string and st[5] must be '', while it is still R.
If your compiler uses range-checking, you’ll get run-time error trying to read past the string’s end. Otherwise you’ll just get whatever garbage is in that memory space. No wonder that it’s still occupied by the same character that was there before.
st before deleting was 5ERROR, after deleting it’s 4ERORR (string length comes first), so R is still there. If delete copied the string instead of shuffling it in place, you’d get random garbage.