Variables 1. Copy semantics is the assignment copies all components of the composite value into the corresponding components of the composite variable. 2. Reference semantics is the assignment makes the composite variable contain a pointer to the composite value. 3. Local variable is the variable whose lifetime is an activation of the block containing that variable’s declaration: the variable is created on entry to the block, and it is destroyed on exit from the block. 4. Global variable is the variable whose lifetime is the program’s entire run-time: the variable is created when the program starts, and it is destroyed when the program stops. 5. global variable or local variable is the variable which is created by a declaration, and has an identifier 6. heap variable is the variable whose lifetime extends from its creation until it is destroyed or it becomes unreachable 7. Heap variable is an anonymous variable which is accessed through a pointer and it is created by an expression or command. 8. Static array is an array variable whose index range is fixed at compile-time. 9. dynamic array is an array variable whose index range is fixed at the time when the array variable is created 10. Flexible array is an array variable whose index range is not fixed at all. 11. pointer is a reference to a particular variable. 12. pointer’s referent is the variable to which a pointer refers. 13. null pointer is a special pointer value that has no referent. 14. dangling pointer is a pointer to a variable that has been destroyed. 1. The simple variables store: a. Primitive values b. composite values c. pointers d. Primitive values and pointers 2. Composite variables in C++ or Java are: a. structure b. Primitive variables c. array d. a+c 3. Structure variable (S) can be selectively updated by assignments form: a. S.I := E1; c. S = E4; b. S[E2] := E3; d. none 4. Structure variable (S) can be totally updated by assignments form: a. S.I := E1; c. S = E4; b. S[E2] := E3; 5. Array variable (A) can be selectively updated by assignments form: a. A.I := E1; b. A = E4; c. A[E2] := E3; 6. Array variable (A) can be totally updated by assignments form: a. A.I := E1; c. A = E4; b. A[E2] := E3; 7. The totally updated of array in ADA is a. Possible c. possible if the two arrays have the same length b. Not possible 8. The totally updated of array in C++ is a. Possible c. possible if the two arrays have the same length b. Not possible 9. The totally updated of array in Java is a. Possible c. possible if the two arrays have the same length b. Not possible 10. The arrays in ADA are a. Static arrays b. Both static and dynamic arrays c. Flexible arrays d. dynamic arrays 11. The arrays in C++ are c. Static arrays d. Both static and dynamic arrays c. Flexible arrays d. dynamic arrays 12. The arrays in JAVA are e. Static arrays f. Both static and dynamic arrays c. Flexible arrays d. dynamic arrays 13. the allocator command in C++,Java and Ada a. ‘new …’ c. ‘free …’ b. ‘malloc …’ d. ‘unchecked_deallocation …’ 14. the allocator command in C a. ‘new …’ b. ‘malloc …’ c. ‘free …’ d. ‘unchecked_deallocation …’ 15. the deallocator command in C a. ‘new …’ b. ‘malloc …’ c. ‘free …’ d. ‘unchecked_deallocation …’ 16. the deallocator command in ADA a. ‘new …’ b. ‘malloc …’ c. ‘free …’ d. ‘unchecked_deallocation …’ 17. the deallocator command in Java a. ‘new …’ b. ‘malloc …’ c. no deallocator at all 18. “V = E;” in C,C++ and Java is a. assignment command b. function call c. condition command 19. P(E1,E2, , En); is a. assignment command b. function call c. condition command c. ‘free …’ d. ‘unchecked_deallocation …’ d. definite iteration e. Indefinite iteration d. definite iteration e. Indefinite iteration 20. if command is a. assignment command b. function call c. condition command d. definite iteration e. Indefinite iteration 21. while command is a. assignment command b. function call c. condition command d. definite iteration e. Indefinite iteration 22. for command is a. assignment command b. function call c. condition command d. definite iteration e. Indefinite iteration 1. Make a diagram the lifetimes of variables in this program.: int g1; void main() { int g2; … P(); … Q(); … } void P() { float p1; int p2; … Q(); … } void Q() { int q; …} Answer: 2. a. Make a diagram the lifetimes of the local variables in this program. (Note that the formal parameter n is, in effect, a local variable of the factorial function.): void main () { int f; f = fac(3); } int factorial (int n) { int p, i; p = 1; for (i = 2; i <= n; i++) p *= i; return p; } b. Using diagrams show the allocation of storage to the local variables of the programs 3. a. Make a diagram the lifetimes of the local variables in this program. (Note that the formal parameter n is, in effect, a local variable of the factorial function.): void main () { int f; f = fac(3); } int factorial (int n) { if (n > 1) return n * factorial(n-1); else return 1; } b. Using diagrams show the allocation of storage to the local variables of the programs