Home > Net >  How strings differ from massive(array) of chars in Pascal?
How strings differ from massive(array) of chars in Pascal?

Time:12-26

I have a problem. Why I can't assign the value of strings to strings, but with chars it works. Why ^^^^^^? Where's string? Why There's the a[i]? Is it because internal representation of strings and chars?

 program massive.pas;
 
 type
         chars = array [1..255] of char;
 
 var
         s,s1: string;
         ch1,ch2: chars;
         i: integer;
 
 begin
         s1 := '';
         s := 'abrakadabra';
         for i := 1 to 5 do
         begin
                s1[i] := s[i];
                writeln(s1[i],#10,'^^^',s1,'^^^')
         end;
         ch2 := '';
         ch1 := 'abrakadabra';
         for i := 1 to 5 do   
         begin 
                ch2[i] := ch1[i]
                writeln(ch2[i])
         end;    
         writeln('%%%',ch2,'%%%');
         for i := 1 to 5 do 
                writeln('&&&',s1[i],'&&&');
 end.            

*Output

a
^^^^^^
b
^^^^^^
r
^^^^^^
a
^^^^^^
k
^^^^^^
a
b
r
a
k
%%           
  • Related