Skip to main content

Introduction to Programming MCQs with Answers

Practice important Introduction to Programming MCQs with answers and explanations.

Multiple Choice Questions

Q471: How do you deallocate memory allocated with malloc() in C?
  • A: Using free()
  • B: Using delete
  • C: Using new
  • D: Using malloc()
View Answer
A

Q472: What is the primary advantage of using new over malloc() in C++?
  • A: new initializes the allocated memory
  • B: new returns a void pointer
  • C: new does not require a type cast
  • D: new requires the size of memory in bytes
View Answer
C

Q473: How do you allocate memory for an array of 10 int values using new in C++?
  • A: int *arr = new int[10];
  • B: int arr = new int(10);
  • C: int *arr = new int(10);
  • D: int arr[10] = new int;
View Answer
A

Q474: What will the following statement return: new int;?
  • A: A pointer to an int
  • B: A void pointer
  • C: An array of 10 ints
  • D: An integer value
View Answer
A

Q475: How do you properly deallocate memory allocated for an array of objects in C++?
  • A: delete ptr;
  • B: delete[] ptr;
  • C: free(ptr);
  • D: delete ptr[];
View Answer
B

Q476: What is the primary purpose of a constructor in C++?
  • A: To initialize an object
  • B: To deallocate memory
  • C: To allocate memory
  • D: To create a pointer
View Answer
A

Q477: When using new to allocate memory for a class object, what additional step does new perform compared to malloc()?
  • A: Calls the class constructor
  • B: Calls the class destructor
  • C: Initializes memory to zero
  • D: Returns a void pointer
View Answer
A

Q478: What happens if new fails to allocate memory in C++?
  • A: Returns NULL
  • B: Throws a bad_alloc exception
  • C: Returns 0
  • D: Returns an uninitialized pointer
View Answer
B

Q479: How should a destructor handle memory allocated with new?
  • A: It should call delete
  • B: It should call malloc
  • C: It should call free
  • D: It should call new
View Answer
A

Q480: What keyword in C++ ensures that a class member is only accessible from within the class itself?
  • A: public
  • B: private
  • C: protected
  • D: friend
View Answer
B

Test Your Knowledge

Take a timed quiz on Introduction to Programming

🚀 Start Quiz Now