Review Part 3 Data Types and Assignment Statements

advertisement
Review Part 3: Data Types and Assignment Statements
For the following questions, answer True (T) or False (F).
1. A local variable can only be used in its own procedure where it is declared.
2. A global variable cannot be used in a subprocedure.
3. A local variable can have the same name as a global variable.
4. Two local variables in different subprocedures can have the same name.
5. Two local variables in the same subprocedure can have the same name.
6. If a variable is only used in one subprocedure, it should be a local variable of that subprocedure.
Consider the following code fragment (see the code for button P1 in the review workbook):
x = 1
y = 2
x = x + 2
x is 3
y = y + x
y is 5
z = x + y
z is 8
x = x + 1
x is 4
Use these choices for your answers:
A. 3
B. 4
C. 5
D. 6
E. None of the above
7. What is the final value of x?
8. What is the final value of y?
9. What is the final value of z?
For the next set of questions, you need to know how many values can be represented with a given
number of bits. The general answer is that with n bits you can represent 2n values. Here’s a table of the
first few.
Bits
1
Values 2
2
4
3
8
4
16
5
32
6
64
7
128
8
256
9
512
10
1024
10. How many values can be represented with one bit?
A. 0
B. 1
C. 2
D. 3
E. 4
11. How many values can be represented with two bits?
A. 0
B. 1
C. 2
D. 3
E. 4
12. How many values can be represented with three bits?
A. 1
B. 3
C. 8
D. 9
E. 256
13. How many values can be represented with eight bits?
A. 1
B. 8
C. 64
D. 256
E. 1024
Use the following choices for the next set of questions:
A. Double
B. Integer
C. String
D. Boolean
16. What data type would you use for a quantity that is a counting number?
17. What data type would you use for a quantity that is a number for general computations?
18. What data type would you use for a quantity that is a logical value?
19. What data type would you use for a quantity that is a quoted text?
Use the following choices for the next set of questions. In each question, tell what the data type(s) of
the result of using the given operator can be.
A. Double
B. Integer
C. String
D. Boolean
E. Double or Integer
20. The operator +
21. The operator /
22. The operator \
23. The operator &
24. The operator >
25. The operator Not
26. The operator ^
27. What is the type of the expression varA & varB?
28. In the expression varA & varB, what type would varA be?
29. What would you expect the type of the expression varA mod 4 to be?
30. In the expression varA mod 4, what would you expect the type of varA be?
31. What is the type of the expression varA >= varB?
Download