The Student Room Group

Help!

4. The following code is part of a high level program to manipulate text:
Var S1: String
Var S2: String
Var Ptr: Integer
Var L: String

S1 := “PAT”
S2 := “” {“” denotes an empty string}

For Ptr := 1 To 3 Do
L := Copy (S1, Ptr)
S2 := Concat (L, S2)
EndFor

If S1 = S2
Then Print (‘True’)
Else Print (‘False’)
EndIf



(c) Dry run the above code by completing the table below.
S1   Ptr   L   S2
"PAT"   ?   ?    ""
?    1    "P"    "P"
?    ?    ?    ?
?    ?    ?    ?
Printed Output   ?


THX!!

S1    Ptr   L    S2
"PAT" NULL  NULL ""
"PAT"  1    "P"   "P"
"PAT"  2    "A"   "AP"
"PAT"  3    "T"   "TAP"

Printed Output   FALSE


It's really not hard.
Reply 2
Thx~

Latest

Trending

Trending