Skip to main content

Introduction to Programming MCQs with Answers

Practice important Introduction to Programming MCQs with answers and explanations.

Multiple Choice Questions

Q611: What happens to a static variable's value when a function is called multiple times?
  • A: It is reset to its initial value each time
  • B: It is incremented and preserved across calls
  • C: It is destroyed and recreated on each call
  • D: It is not visible to the function
View Answer
B

Q612: In the given code, what will be the output of the staticVarFun() function call inside a loop?
  • A: The value of i will always be 1
  • B: The value of i will increment with each call
  • C: The value of i will be random
  • D: The function will not print anything
View Answer
B

Q613: What will be the output of the nonstaticVarFun() function when called in a loop?
  • A: The value of i will increment with each call
  • B: The value of i will always be 1
  • C: The value of i will be random
  • D: The function will not print anything
View Answer
B

Q614: How does the destruction of static objects in functions differ from local objects?
  • A: Static objects are destroyed when the function exits
  • B: Static objects are destroyed at the end of the program
  • C: Static objects are not destroyed
  • D: Static objects are destroyed immediately
View Answer
B

Q615: What happens if you use the static keyword with class data members?
  • A: Each object has its own copy of the static member
  • B: Only one copy of the static member exists for the class
  • C: Static members are not accessible from objects
  • D: Each static member is initialized per object
View Answer
B

Q616: How should you initialize a static data member of a class?
  • A: Inside the constructor of the class
  • B: Inside the destructor of the class
  • C: Outside the class definition using the scope resolution operator
  • D: Inside each object's constructor
View Answer
C

Q617: When should you use the class name to access a static member?
  • A: When you need to refer to the member across all objects
  • B: When the member is private
  • C: When you want to initialize it
  • D: When the member is not static
View Answer
A

Q618: In the provided program, what is the order of destruction of objects?
  • A: Static objects, then local objects, then global objects
  • B: Global objects, then static objects, then local objects
  • C: Local objects, then static objects, then global objects
  • D: Global objects, then local objects, then static objects
View Answer
B

Q619: What is a common use case for static data members in a class?
  • A: To store information specific to each object
  • B: To maintain a count of objects created
  • C: To store temporary data
  • D: To manage dynamic memory allocation
View Answer
B

Q620: What does a pointer in C++ store?
  • A: The value of a variable
  • B: The memory address of a variable
  • C: The size of a variable
  • D: The type of a variable
View Answer
B

Test Your Knowledge

Take a timed quiz on Introduction to Programming

🚀 Start Quiz Now