Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

problems on records

badingbading Member Posts: 9
[b][red]This message was edited by bading at 2004-3-17 8:2:43[/red][/b][hr]
Consider the following type of declarations:

type Sample=Record
F1:integer;
F2:integer;
end;
var x1,x2:sample;

what will be the output of the following piece of code be(provided that it is embedded in a complete Pascal program that includes the preceeding type declarations)?


x1.f1:=5;x1.f2:='A';
wrteln(x1.f1,x1.f2);
x2:=x1;
x2.f1:=6;
writeln(x2.f1,x2.f2);


Comments

  • zibadianzibadian Member Posts: 6,349
    : [b][red]This message was edited by bading at 2004-3-17 8:2:43[/red][/b][hr]
    : Consider the following type of declarations:
    :
    : type Sample=Record
    : F1:integer;
    : F2:integer;
    : end;
    : var x1,x2:sample;
    :
    : what will be the output of the following piece of code be(provided that it is embedded in a complete Pascal program that includes the preceeding type declarations)?
    :
    :
    : x1.f1:=5;x1.f2:='A';
    : wrteln(x1.f1,x1.f2);
    : x2:=x1;
    : x2.f1:=6;
    : writeln(x2.f1,x2.f2);
    :
    :
    :
    It won't run because f2 isn't a string or a char, so the assignment x1.f2 := 'A'; will give a design-time error.
  • badingbading Member Posts: 9
    : : [b][red]This message was edited by bading at 2004-3-17 8:2:43[/red][/b][hr]
    : : Consider the following type of declarations:
    : :
    : : type Sample=Record
    : : F1:integer;
    : : F2:integer;
    : : end;
    : : var x1,x2:sample;
    : :
    : : what will be the output of the following piece of code be(provided that it is embedded in a complete Pascal program that includes the preceeding type declarations)?
    : :
    : :
    : : x1.f1:=5;x1.f2:='A';
    : : wrteln(x1.f1,x1.f2);
    : : x2:=x1;
    : : x2.f1:=6;
    : : writeln(x2.f1,x2.f2);
    : :
    : :
    : :
    : It won't run because f2 isn't a string or a char, so the assignment x1.f2 := 'A'; will give a design-time error.
    : your right zibadian!now,how about if we are going to change f2 a type
    character,what will be the output?
    your friend,
    BADING

  • zibadianzibadian Member Posts: 6,349
    : : : [b][red]This message was edited by bading at 2004-3-17 8:2:43[/red][/b][hr]
    : : : Consider the following type of declarations:
    : : :
    : : : type Sample=Record
    : : : F1:integer;
    : : : F2:integer;
    : : : end;
    : : : var x1,x2:sample;
    : : :
    : : : what will be the output of the following piece of code be(provided that it is embedded in a complete Pascal program that includes the preceeding type declarations)?
    : : :
    : : :
    : : : x1.f1:=5;x1.f2:='A';
    : : : wrteln(x1.f1,x1.f2);
    : : : x2:=x1;
    : : : x2.f1:=6;
    : : : writeln(x2.f1,x2.f2);
    : : :
    : : :
    : : :
    : : It won't run because f2 isn't a string or a char, so the assignment x1.f2 := 'A'; will give a design-time error.
    : : your right zibadian!now,how about if we are going to change f2 a type
    : character,what will be the output?
    : your friend,
    : BADING
    :
    :
    If you change the f2 into a char, then the code will compile, but you should be able to predict the output yourself.
    This kind of exercise is quite important, since it learns you to read the code as the compiler does and be able to spot possible errors during the inevitable debug fase of the programming process. I've helped people who could not read their own code, and just tried and tried (and tried) until the program did what they wanted to do. They often were 10 to 50 times longer busy with debugging than necessary.
Sign In or Register to comment.