Suppose there are three variables XY and Z with these types

Suppose there are three variables X,Y and Z with these types:

X:integer that is divisble by 3

Y:integer thsat is divisible by 12

Z:integer

For each of the following, knowing nothing about the values of the variables excpet their types, answer whether a langusage system can tell before running the program whether the assignment is safe? why or why not?

1.Z: = X

2.X := Z

3.X := X + 3

4.X := X + Z

Solution

1.Z:=X

Its safe.Because X is an integer.

2.X:=Z

Its not safe.Because X cannot take all integers.

3.X:=X+3

Its safe.Because X+3 is divisible by 3

4.X:=X+Z

Its not safe.Because for example if we take X=6,Z=2 then X+Z=6+2=8

which is not divisible by 3

Suppose there are three variables X,Y and Z with these types: X:integer that is divisble by 3 Y:integer thsat is divisible by 12 Z:integer For each of the follo

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site