Skip to main content

Introduction to Programming MCQs with Answers

Practice important Introduction to Programming MCQs with answers and explanations.

Multiple Choice Questions

Q601: How do you define a parameter-less user-defined manipulator?
  • A: ostream& manipulator_name (ostream& os)
  • B: ostream manipulator_name (ostream& os)
  • C: ostream& manipulator_name (ostream os)
  • D: ostream manipulator_name (ostream os)
View Answer
A

Q602: What does the endl manipulator do?
  • A: Inserts a tab character
  • B: Inserts a newline and flushes the buffer
  • C: Adds a beep sound
  • D: Adds a space between numbers
View Answer
B

Q603: In the provided code, what does the tab manipulator do?
  • A: Inserts a newline
  • B: Inserts a tab character
  • C: Inserts a star
  • D: Inserts a space between elements
View Answer
B

Q604: Which function is used to create a static variable within a function in C++?
  • A: static
  • B: global
  • C: local
  • D: auto
View Answer
A

Q605: What is the main purpose of using static variables inside functions?
  • A: To maintain the variable's value between function calls
  • B: To create variables that are only accessible in main
  • C: To ensure variables are always initialized
  • D: To allocate memory dynamically
View Answer
A

Q606: What will happen if you declare a static variable inside the main function?
  • A: It will be initialized only once during the program's execution
  • B: It will be visible only in the main function
  • C: It will be accessible only inside loops
  • D: It will be destroyed after the main function exits
View Answer
B

Q607: Which keyword is used to declare a variable that persists between function calls?
  • A: const
  • B: auto
  • C: static
  • D: extern
View Answer
C

Q608: In the context of user-defined manipulators, what does the flush function do?
  • A: Clears the buffer
  • B: Inserts a tab character
  • C: Inserts a newline
  • D: Ends the current line
View Answer
A

Q609: What is the correct way to overload the stream insertion operator (<<) for user-defined manipulators?
  • A: ostream& operator << (ostream& os, MyClass& obj)
  • B: ostream& operator << (MyClass& obj, ostream& os)
  • C: ostream& operator << (ostream& os, MyClass obj)
  • D: ostream& operator << (MyClass obj, ostream& os)
View Answer
A

Q610: What is the primary purpose of the static keyword in a function?
  • A: To create a global variable
  • B: To make a variable accessible throughout the file
  • C: To maintain a variable's state across function calls
  • D: To allocate dynamic memory
View Answer
C

Test Your Knowledge

Take a timed quiz on Introduction to Programming

🚀 Start Quiz Now