Quick Test 6: Assignment and Constants



 
 

1. When we want to assign a value of 8.3 to a variable r we do this with

r := 8.3;
r = 8.3;
r == 8.3;.
8.3 -> r;

2. After the assignment of question 1, which of the following lines of PASCAL will produce 
   8.3000

writeln(8.3000);
writeln(6*r,4);
writeln('%6.4f', r);
writeln(r:6:4);


 

3. What is wrong with the following program?

PROGRAM Error1;

VAR x: real;
CONST c = 1.0;

begin
  x*x := 2*c;
end.

A constant cannot change a value
The left side of the := can only contain a (single) variable
Variable x is not well defined
The right side of := cannot contain constants

4. What is wrong with the following program?

PROGRAM Error2;

VAR x: real;
CONST c = 2.0;

begin
  c := 2*x*c + 1;
end.

A constant cannot change a value
The right side of the := can only contain a (single) variable
The equation does not have a solution
Constants must be written with CAPITALS


 
 

5. What is the output of the next program

PROGRAM Variable;

VAR x: real;
CONST C = 1.0;

begin
  x := C + 1;
  x := 2;
  x := x + 3;
  writeln(x:4:1);
end.

7.0
5.0
3.0
1.0