Mittwoch, 13. Mai 2015

Data types and operators

Two variables given, b of type boolean and i of type integer. Which of the following statements are correct?

[A] b and (i > 0)

Correct.

[B] i > 0 and b 

"0 and b" binds before "i >". "and" requires operands of type boolean.
(i > 0) and b would be correct.

[C] i / 3

Correct. But why?
The standard operators to be used with integers are +, -, *, div and mod.

What about /, which is part of the operators to be used with the data type real?
It looks like the operator can be used with integers as well. 
Use operands of type integer with / and you will get a result of type real.


[D] (i > 0) or b = false

Correct. 
i > 0: boolean
(i > 0) or b: boolean

[E] i div 3.0

div requires operands of type integer.

Keine Kommentare:

Kommentar veröffentlichen