Professional Documents
Culture Documents
This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) focuses on
“Automatic Variable”.
View Answer
Answer: c
Explanation: 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.
advertisement
2. 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
View Answer
Answer: b
Explanation: 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.
View Answer
Answer: d
Explanation: The automatic variables scope is limited only within the block or the function where those are
de ned. This is the property of all the automatic variables.
View Answer
Answer: a
Explanation: The automatic variables are hidden from the called function. Even if passed by reference or
address, the address of the variable is used and not the actual variable of calling function. Automatic
variables can be const or variable.
5. If an automatic variable is created and then a function is called then ________________
a) The automatic variable created gets destroyed
b) The automatic variable doesn’t get destroyed
c) The automatic variable may or may not get destroyed
d) The automatic variable can’t be used in this case
View Answer
Answer: b
Explanation: The automatic variables are saved till the called function gets executed. This is done so as to
ensure that the program can continue its execution after the called function is returned. The automatic
variables gets destroyed only if those go out of scope.
advertisement
6. 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
View Answer
Answer: c
Explanation: 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.
7. 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
View Answer
Answer: b
Explanation: The static members can’t be automatic. This is because the automatic variables are created and
destroyed with each call to a speci c function. But the static members remain throughout the execution of
program once created.
View Answer
Answer: d
Explanation: 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.
View Answer
Answer: c
Explanation: 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.
advertisement
10. Constructor of automatic variables is called ____________________
a) When execution reaches the place of declaration of automatic variables
b) When the program is compiled
c) When the execution is just started
d) Just before the execution of the program
View Answer
Answer: a
Explanation: Only when the execution reaches the place where the automatic variable was declared, the
constructor is called. This is to ensure that the memory is not allocated if not needed. The memory is
allocated and then destroyed as soon as it goes out of scope.
View Answer
Answer: d
Explanation: 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.
View Answer
Answer: b
Explanation: 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.
13. Which error is produced if the automatic variables are used without declaration?
a) Unde ned symbol
b) Memory error
c) Type mismatch
d) Statement missing
View Answer
Answer: a
Explanation: If the automatic variables are used without declaration or are used before the declaration then
the compiler throws an error. The error that the symbol is unde ned. The compiler must know everything
before that can be used.
advertisement
14. In Perl, using which operator are the local variables created?
a) Dot
b) Arrow
c) Scope resolution
d) my
View Answer
Answer: d
Explanation: The language perl supports local variables but the concept is bit di erent. And if the values are
not assigned to the local variables then it contains undef value.
15. How are automatic variables di erent from the instance variables?
a) Automatic variables are initialized automatically but instances are not
b) Automatic variables are given zero values initially and not instances
c) Instance variables have to be initialized explicitly and automatic implicitly
d) Instance variables are initialized implicitly while automatic are not
View Answer
Answer: d
Explanation: The automatic variables have to be initialized explicitly. But in case of instances, those are
initialized automatically during execution of the program. The conventions are mandatory.
Sanfoundry Global Education & Learning Series – Object Oriented Programming (OOPs).
To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+ Multiple Choice
Questions and Answers.
Participate in the Sanfoundry Certi cation contest to get free Certi cate of Merit. Join our social networks
below and stay updated with latest contests, videos, internships and jobs!
advertisement
Recommended Posts:
1. C Programming Examples on Data-Structures
2. C# Programming Examples on Matrix
3. C# Programming Examples on Delegates
4. Java Programming Examples on Exception Handling
5. C Programming Examples on Numerical Problems & Algorithms
6. C# Programming Examples on Mathematics
7. C# Programming Examples on Events
8. C# Programming Examples on Strings
9. C Programming Examples on Bitwise Operations
10. C Tutorials
11. Java Programming Examples on Multithreading
12. C# Programming Examples on Functions
13. C Programming Examples on File Handling
14. Java Programming Examples on Java.Lang
15. C# Programming Examples on Interfaces
16. C# Programming Examples on Exceptions
17. C# Programming Examples on Threads
18. Java Programming Examples on Inheritance
19. Java Programming Examples on Classes
20. Object Oriented Programming Questions and Answers
advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and
CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about
competency developments in these areas. He lives in Bangalore and delivers focused
training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers,
Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies,
SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him
@ LinkedIn
Name*
Email*
Subscribe
About | Certi cations | Internships | Jobs | Privacy Policy | Terms | Copyright | Contact