Test Series - oops

Test Number 74/78

Q: The memory for automatic variables ________________
A. Have to be allocated and deallocated explicitly
B. Are allocated and deallocated automatically
C. Is never actually allocated
D. Are never safe
Solution: The memory is allocated and deallocated automatically for the automatic variables. As soon as the variable comes in scope, the memory is allocated. The variables are destroyed as soon as those go out of scope.
Q: What are automatic variables?
A. Global variables
B. Implicit/temporary variables
C. Local variables
D. System variables
Solution: The local variables are also known as automatic variables. The variables in any local scope that are created and destroyed as the program executes its scope.
Q: The automatic variables _________________________
A. Must be declared after its use
B. Must be declared before using
C. Must be declared, can be anytime
D. Must not be initialized
Solution: All the automatic variables in a program must be declared before their use. The compiler won’t allow any use of variable if those are not declared before their use.
Q: In Perl, using which operator are the local variables created?
A. Dot
B. Arrow
C. Scope resolution
D. my
Solution: The language perl supports local variables but the concept is bit different. And if the values are not assigned to the local variables then it contains undef value.
Q: Scope of an automatic variable _______________
A. Is actually the whole program
B. Is actually never fixed
C. Is always equal to the whole program execution
D. Is actually function or block in which it is defined
Solution: The automatic variables scope is limited only within the block or the function where those are defined. This is the property of all the automatic variables.
Q: The static variables of a function ________________
A. Are also automatic variables
B. Are not automatic variables
C. Are made automatic by default
D. Can be made automatic explicitly
Solution: The static members can’t be automatic. This is because the automatic variables are created and destroyed with each call to a specific function. But the static members remain throughout the execution of program once created.
Q: What values does uninitialized automatic variables contain?
A. Null value
B. Void value
C. Undefined/Garbage
D. Zero value
Solution: The automatic variable which are not initialized, contain garbage value. If we just declare a variable and try to print its value, the result is some unknown value. The value is garbage as that was not expected value.
Q: All variables declared within a block ____________________
A. Are not always automatic
B. Can be made non-automatic
C. Are static by default
D. Are automatic by default
Solution: The variables declared inside a block, are make automatic by default. This is to ensure that the variables get destroyed when not required. The variables remain live only till those are required, the life is dependent on the scope of a variable.
Q: Does java contain auto or register keywords?
A. Yes, for declaring every type of variable
B. Yes, only to declare cache registers
C. No, because java doesn’t support automatic variables
D. No, java supports local variable concept
Solution: The auto and register keywords are not supported in java. Though the same is allowed in java without specifying any of those keywords. The variables are local variables. But java makes it mandatory to initialize all of the local variables in a program.
Q: Where are the automatic variables stored if another function is called in between the execution of the program?
A. Heap
B. Queue
C. Stack
D. Temp variable
Solution: All the automatic variables are stored in a new stack entry as soon as their scope is created. If another function is called, the present data is saved in stack and new entry in stack is made for the called function. When the function returns, the automatic variables are used again from where those were left.

You Have Score    /10