Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Chapter: 39
Q621:
How do you obtain the address of a variable in C++?
A. Using *
B. Using &
C. Using ->
D. Using .
Correct Answer:
B
Chapter: 39
Q622:
Which operator is used for dynamic memory allocation in C++?
A. malloc
B. calloc
C. new
D. alloc
Correct Answer:
C
Chapter: 39
Q623:
What is the role of the delete operator in C++?
A. To allocate memory
B. To deallocate memory
C. To create a new pointer
D. To initialize memory
Correct Answer:
B
Chapter: 39
Q624:
How is a reference different from a pointer?
A. A reference can point to nothing
B. A reference must always point to something
C. A reference is a type of pointer
D. A reference is a special pointer
Correct Answer:
B
Chapter: 39
Q625:
What does call by value mean in function arguments?
A. Passing the address of the variable
B. Passing the variable itself
C. Passing a copy of the variable
D. Passing a reference to the variable
Correct Answer:
C
Chapter: 39
Q626:
When is a copy constructor used?
A. When copying a reference
B. When copying a pointer
C. When creating a copy of an object
D. When deleting an object
Correct Answer:
C
Chapter: 39
Q627:
What happens if you assign one object to another without an overloaded assignment operator?
A. The new object is completely independent
B. The two objects point to the same memory
C. The original object is deleted
D. The memory is automatically freed
Correct Answer:
B
Chapter: 39
Q628:
What does new int [10] do in C++?
A. Allocates memory for 10 integers
B. Allocates memory for 10 characters
C. Deallocates memory for 10 integers
D. Deallocates memory for 10 characters
Correct Answer:
A
Chapter: 39
Q629:
How should you handle memory deallocation for arrays allocated with new?
A. delete p
B. delete [] p
C. free(p)
D. delete(p)
Correct Answer:
B
Chapter: 40
Q630:
When is the destructor of a contained object called in relation to the containing object?
A. Before the containing object
B. After the containing object
C. Simultaneously with the containing object
D. Independently of the containing object
Correct Answer:
B
Chapter: 40
Q631:
In the PersonInfo class example, what is the sequence of constructor calls when an object is created?
A. Date constructor first, then PersonInfo constructor
B. PersonInfo constructor first, then Date constructor
C. Both constructors are called simultaneously
D. PersonInfo constructor, then Date destructor
Correct Answer:
A
Chapter: 40
Q632:
How do you initialize a member object using the initializer list in a class constructor?
A. By using a setter method
B. By assigning values directly in the constructor body
C. By using the initializer list syntax
D. By calling a static method of the member object
Correct Answer:
C
Chapter: 40
Q633:
What is the correct way to declare and initialize a constant member object in a class?
A. Use a default constructor and initialize in the body
B. Use a parameterized constructor and initializer list
C. Use a setter method
D. Use a static member initializer
Correct Answer:
B
Chapter: 40
Q634:
In the Matrix, Row, and Column example, which object is constructed first when creating a Matrix object?
A. Matrix object
B. Row object
C. Column object
D. All objects are constructed simultaneously
Correct Answer:
C
Chapter: 40
Q635:
When a member class is declared as private in a surrounding class, where can it be accessed?
A. Only within the surrounding class
B. From outside the surrounding class
C. From any other class
D. Only by the public members of the surrounding class
Correct Answer:
A
Chapter: 40
Q636:
Which of the following statements is true about nested classes in C++?
A. Nested classes are allocated memory when declared
B. Nested classes must be static
C. Nested classes can be private or public
D. The outer class has no control over the inner class
Correct Answer:
C
Chapter: 40
Q637:
How do nested classes interact with the outer class in terms of member access?
A. They have unrestricted access to all outer class members
B. They can access only public members of the outer class
C. They can access only private members of the outer class
D. They can access private members of the outer class if declared as friends
Correct Answer:
B
Chapter: 40
Q638:
What is the output of the program where a Matrix object is created with nested Row and Column objects?
A. Column created, Row created, Matrix created, and all destructors in reverse order
B. Matrix created, Row created, Column created, and all destructors in reverse order
C. Column created, Matrix created, Row created, and all destructors in reverse order
D. All objects are created and destroyed simultaneously
Correct Answer:
A
Chapter: 40
Q639:
How are member functions of nested classes defined in C++?
A. They must be defined within the nested class only
B. They can be defined either inside or outside the outer class
C. They are defined as static methods only
D. They must be defined outside the nested class
Correct Answer:
B
Chapter: 41
Q640:
What is the main purpose of using templates in C++?
A. To enable code reuse with specific data types
B. To define macros for different data types
C. To provide a way to create generic functions and classes
D. To handle complex class inheritance
Correct Answer:
C