SlideShare a Scribd company logo
Object Oriented Programming using C++ / C Plus Plus QUIZ
Object Oriented Programming using C++ / C Plus Plus QUIZ
OOPs
QUIZ
MCQ
True False
Questions
Fill in the Blanks
Assertion
Reasoning
01
02
04
03
Output Finding
05
MCQ
True False
Questions
Fill in the Blanks
Assertion
Reasoning
01
02
04
03
Output Finding
05
MCQ
01
Which of the following operators is used to access
members of a class in C++?
Question 1
A)->
B).
C) ::
D) [ ]
A) ->
Which of the following operators is used to access
members of a class in C++?
Question 1
1. int main()
2. void main()
3. None
4. Both 1 and 2
Which of the following is the correct
implementation / use of main() function?
Question 2
1. int main()
Which of the following operators is used to access
members of a class in C++?
Question 2
1. The program has encountered an
error.
2. The program has executed
successfully.
3. It has no specific meaning.
4. It causes the program to
terminate immediately.
What does return 0; signify in the main function?
Question 3
The program has executed successfully.
What does return 0; signify in the main function?
Question 3
1. The main function can only create
instances of classes.
2. The main function cannot use class
methods.
3. The main function can access static
members of classes directly.
4. The main function must be defined
within a class.
Which of the following statements is true
regarding the
use of the main function in object-oriented
programming?
Question 4
The main function can access static
members of classes directly
Which of the following statements is true
regarding the
use of the main function in object-oriented
programming?
Question 4
A. The function continues to execute any
remaining statements after the return.
B. The function exits immediately, and control
is passed back to the calling function.
C. The function returns control to the main
function.
D. The function throws an exception.
In C++, what happens when a return statement is encountered
in a function?
Question 5
The function exits immediately, and
control is passed back to the calling
function.
In C++, what happens when a return statement is encountered
in a function?
Question 5
A. The return statement can be used to return
a value from a function.
B. A void function can have a return statement
without any value.
C. If a function returns void, it cannot have a
return statement.
D. When a return statement is executed, the
function terminates immediately.
Which of the following statements about the return statement in C++
is false?
Question 6
If a function returns void, it cannot
have a return statement.
Which of the following statements about the return statement in C++
is false?
Question 6
A) Only the constructor
B) Only the destructor
C) Both constructor and destructor
D) Copy constructor and assignment
operator
If a class has dynamically allocated memory, which of the following
should be implemented?
Question 6
Copy constructor and
assignment operator
Which of the following statements about the return statement in C++
is false?
Question 6
A) All statements are Valid.
B) A derived class can override the constructor
of a virtually inherited class.
Which of the following statements is NOT valid in the context of virtual
inheritance in C++?
Question 7
C) A virtually inherited base class's constructor
is called only once, regardless of how many
derived classes inherit it.
D) In virtual inheritance, the most derived class
is responsible for initializing the virtually
inherited base class.
A derived class can override the
constructor of a virtually inherited
class.
Which of the following statements is NOT valid in the context of virtual
inheritance in C++?
Question 7
MCQ
True False
Questions
Fill in the Blanks
Assertion
Reasoning
01
02
04
03
Output Finding
05
MCQ
True False
Questions
Fill in the Blanks
Assertion
Reasoning
01
02
04
03
Output Finding
05
True
False
02
Question 1
Friend functions can be inherited by derived
classes.
TRUE FALSE
Question 1
Friend functions can be inherited by derived
classes.
TRUE FALSE
Question 2
The scope of a variable declared inside a
function in C++ is Class scope.
TRUE FALSE
Question 2
The scope of a variable declared inside a
function in C++ is Class scope.
TRUE FALSE
Question 3
The size of int data type is always 4 bytes,
irrespective of the system architecture.
TRUE FALSE
Question 3
The size of int data type is always 4 bytes,
irrespective of the system architecture.
TRUE FALSE
MCQ
True False
Questions
Fill in the Blanks
Assertion
Reasoning
01
02
04
03
Output Finding
05
MCQ
True False
Questions
Fill in the Blanks
Assertion
Reasoning
01
02
04
03
Output Finding
05
Fill in
the
Blanks
03
Question 1
In a class, a static member function can only access ______ data members
of the class, because it does not have access to the ______ pointer.
Question 1
In a class, a static member function can only access ______ data members
of the class, because it does not have access to the ______ pointer.
1. static 2. this
Question 2
To call a static member function multiply from a class named
MathOperations, you can write MathOperations::multiply(4, 5);.
This syntax is possible because multiply is associated with the ____ itself,
not with any specific ____.
Question 2
To call a static member function multiply from a class named
MathOperations, you can write MathOperations::multiply(4, 5);.
This syntax is possible because multiply is associated with the ____ itself,
not with any specific ____.
1. Class 2. Object
Question 3
In C++, the operator ___ cannot be overloaded. (Choose one: ::, ++, +, -)
Question 3
In C++, the operator ___ cannot be overloaded. (Choose one: ::, ++, +, -)
::
Question 4
In C++, the operator ___ cannot be overloaded. (Choose one: ::, ++, +, -)
Question 4
In C++, the operator ___ cannot be overloaded. (Choose one: ::, ++, +, -)
::
Question 5
When overloading an operator as a member function, the left-hand operand
is always __________.
Question 5
When overloading an operator as a member function, the left-hand operand
is always __________.
this
MCQ
True False
Questions
Fill in the Blanks
Assertion
Reasoning
01
02
04
03
Output Finding
05
MCQ
True False
Questions
Fill in the Blanks
Assertion
Reasoning
01
02
04
03
Output Finding
05
Assertion
Reasoning
04
Static member functions cannot
be
virtual.
Static member functions are
associated with the class, not
with
specific instances of the class.
ASSERTION REASON
A false, R true
A true, R false Both False
Both True
Question 1
Static member functions cannot
be
virtual.
Static member functions are
associated with the class, not
with
specific instances of the class.
ASSERTION REASON
A false, R true
A true, R false Both False
Both True
Question 1
Destructors can have return
types in
C++.
Destructors must return void
because they are automatically
called by the system and are
not
meant to return values.
ASSERTION REASON
Both True A false, R true
A true, R false Both False
Question 2
Destructors can have return
types in
C++.
Destructors must return void
because they are automatically
called by the system and are
not
meant to return values.
ASSERTION REASON
Both True A false, R true
A true, R false Both False
Question 2
MCQ
True False
Questions
Fill in the Blanks
Assertion
Reasoning
01
02
04
03
Output Finding
05
MCQ
True False
Questions
Fill in the Blanks
Assertion
Reasoning
01
02
04
03
Output Finding
05
Output
Finding
05
55
int x = 5;
x = x+++++x;
Find the output by
analyzing the code.
Question 1
56
int x = 5;
x = x+++++x;
Find the output by
analyzing the code.
Answer:
Undefined behavior
Question 1
57
Find the output by
analyzing the code.
class Test {
public:
int x;
Test(int value) : x(value) {
cout << "Constructor called for x = " << x << endl;
}
~Test() {
cout << "Destructor called for x = " << x << endl;
}
};
int main() {
Test t1(10);
{
Test t2(20);
}
cout << "End of main" << endl;
return 0;
}
Question 2
58
Find the output by
analyzing the code.
class Test {
public:
int x;
Test(int value) : x(value) {
cout << "Constructor called for x = " << x << endl;
}
~Test() {
cout << "Destructor called for x = " << x << endl;
}
};
int main() {
Test t1(10);
{
Test t2(20);
}
cout << "End of main" << endl;
return 0;
}
Ans:
Constructor called for x = 10
Constructor called for x = 20
Destructor called for x = 20
End of main
Destructor called for x = 10
Question 2
59
Find the output by
analyzing the code.
class MyClass {
int* ptr;
public:
MyClass(int size) {
ptr = new int[size]; // Dynamically allocate memory
cout << "Memory allocated for " << size << " integers." << endl;
}
~MyClass() {
delete[] ptr; // Deallocate memory
cout << "Memory deallocated." << endl;
}
};
int main() {
MyClass obj(5); // Dynamically allocate memory for 5 integers
return 0;
}
Question 3
60
Find the output by
analyzing the code.
class MyClass {
int* ptr;
public:
MyClass(int size) {
ptr = new int[size]; // Dynamically allocate memory
cout << "Memory allocated for " << size << " integers." << endl;
}
~MyClass() {
delete[] ptr; // Deallocate memory
cout << "Memory deallocated." << endl;
}
};
int main() {
MyClass obj(5); // Dynamically allocate memory for 5 integers
return 0;
}
Answer:
The output will be:
Memory allocated for 5 integers.
Memory deallocated.
Question 3
61
Find the output by
analyzing the code.
class Complex {
public:
int real, imag;
Complex(int r, int i) : real(r), imag(i) {}
Complex operator*(const Complex& c) {
return Complex(real * c.real - imag * c.imag, real * c.imag +
imag * c.real);
}
void display() { cout << real << "+" << imag << "i "; }
};
int main() {
Complex c1(2, 3), c2(4, 5);
Complex c3 = c1 * c2;
c3.display();
return 0;
}
Question 4
62
Find the output by
analyzing the code.
class Complex {
public:
int real, imag;
Complex(int r, int i) : real(r), imag(i) {}
Complex operator*(const Complex& c) {
return Complex(real * c.real - imag * c.imag, real * c.imag +
imag * c.real);
}
void display() { cout << real << "+" << imag << "i "; }
};
int main() {
Complex c1(2, 3), c2(4, 5);
Complex c3 = c1 * c2;
c3.display();
return 0;
}
Answer:
-7+22i
Question 4
END OF QUIZ
Thank you.

More Related Content

DOC
C++ questions
anujchouksey
 
PPTX
PART - 1 Cpp programming Solved MCQ
Knowledge Center Computer
 
PPTX
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 1
Knowledge Center Computer
 
PPTX
Part - 2 Cpp programming Solved MCQ
Knowledge Center Computer
 
PDF
Starting Out with C++ Early Objects 9th Edition Gaddis Test Bank
anpebinthi21
 
PDF
C data_structures
Tushar Desarda
 
PPTX
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
Knowledge Center Computer
 
DOCX
A) member functions B) member variables C) constructor and destructor.docx
andyb37
 
C++ questions
anujchouksey
 
PART - 1 Cpp programming Solved MCQ
Knowledge Center Computer
 
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 1
Knowledge Center Computer
 
Part - 2 Cpp programming Solved MCQ
Knowledge Center Computer
 
Starting Out with C++ Early Objects 9th Edition Gaddis Test Bank
anpebinthi21
 
C data_structures
Tushar Desarda
 
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
Knowledge Center Computer
 
A) member functions B) member variables C) constructor and destructor.docx
andyb37
 

Similar to Object Oriented Programming using C++ / C Plus Plus QUIZ (20)

PDF
200 mcq c++(Ankit dubey)
Ankit Dubey
 
DOCX
GSP 125 Exceptional Education - snaptutorial.com
donaldzs162
 
DOC
GSP 125 Education Specialist / snaptutorial.com
stevesonz146
 
PPTX
Operator overload rr
Dhivya Shanmugam
 
DOC
Gsp 125 Massive Success / snaptutorial.com
NorrisMistryzo
 
DOC
GSP 125 Technology levels--snaptutorial.com
sholingarjosh136
 
DOC
Gsp 125 Enthusiastic Study / snaptutorial.com
Stephenson101
 
DOCX
Gsp 125 Education Organization -- snaptutorial.com
DavisMurphyB85
 
PDF
C++ interview question
Durgesh Tripathi
 
PDF
22316-2019-Summer-model-answer-paper.pdf
PradipShinde53
 
DOCX
GSP 125 RANK Education for Service--gsp125rank.com
claric25
 
PDF
C++ aptitude
chetan_p211
 
PPTX
C++.pptx
AbhimanyuKumarYadav3
 
PDF
Oops Paper
prabhatjon
 
PDF
E5
lksoo
 
PDF
Classes-and-Objects-in-C++.pdf
ismartshanker1
 
DOC
GSP 125 Become Exceptional/newtonhelp.com
bellflower148
 
DOC
GSP 125 Doing by learn/newtonhelp.com
bellflower126
 
DOC
Gsp 125 Future Our Mission/newtonhelp.com
amaranthbeg8
 
DOC
GSP 125 Perfect Education/newtonhelp.com
bellflower169
 
200 mcq c++(Ankit dubey)
Ankit Dubey
 
GSP 125 Exceptional Education - snaptutorial.com
donaldzs162
 
GSP 125 Education Specialist / snaptutorial.com
stevesonz146
 
Operator overload rr
Dhivya Shanmugam
 
Gsp 125 Massive Success / snaptutorial.com
NorrisMistryzo
 
GSP 125 Technology levels--snaptutorial.com
sholingarjosh136
 
Gsp 125 Enthusiastic Study / snaptutorial.com
Stephenson101
 
Gsp 125 Education Organization -- snaptutorial.com
DavisMurphyB85
 
C++ interview question
Durgesh Tripathi
 
22316-2019-Summer-model-answer-paper.pdf
PradipShinde53
 
GSP 125 RANK Education for Service--gsp125rank.com
claric25
 
C++ aptitude
chetan_p211
 
Oops Paper
prabhatjon
 
E5
lksoo
 
Classes-and-Objects-in-C++.pdf
ismartshanker1
 
GSP 125 Become Exceptional/newtonhelp.com
bellflower148
 
GSP 125 Doing by learn/newtonhelp.com
bellflower126
 
Gsp 125 Future Our Mission/newtonhelp.com
amaranthbeg8
 
GSP 125 Perfect Education/newtonhelp.com
bellflower169
 
Ad

More from RAKSHITDOGRA1 (7)

PPTX
Searching & Algorithms IN DATA STRUCTURES
RAKSHITDOGRA1
 
PPTX
OBJECT ORIENTED PROGRAMMING using C++ / CPP
RAKSHITDOGRA1
 
PDF
Presentation on Algorithms and Flowcharts
RAKSHITDOGRA1
 
PDF
Distinction test for functional groups
RAKSHITDOGRA1
 
PDF
Presentation on Poem Analysis of My Mother At Sixty- Six
RAKSHITDOGRA1
 
PDF
Determination of Caffeine In Tea Samples
RAKSHITDOGRA1
 
PDF
Mineral resources in Sikkim ppt
RAKSHITDOGRA1
 
Searching & Algorithms IN DATA STRUCTURES
RAKSHITDOGRA1
 
OBJECT ORIENTED PROGRAMMING using C++ / CPP
RAKSHITDOGRA1
 
Presentation on Algorithms and Flowcharts
RAKSHITDOGRA1
 
Distinction test for functional groups
RAKSHITDOGRA1
 
Presentation on Poem Analysis of My Mother At Sixty- Six
RAKSHITDOGRA1
 
Determination of Caffeine In Tea Samples
RAKSHITDOGRA1
 
Mineral resources in Sikkim ppt
RAKSHITDOGRA1
 
Ad

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 

Object Oriented Programming using C++ / C Plus Plus QUIZ

  • 4. MCQ True False Questions Fill in the Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
  • 5. MCQ True False Questions Fill in the Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
  • 7. Which of the following operators is used to access members of a class in C++? Question 1 A)-> B). C) :: D) [ ]
  • 8. A) -> Which of the following operators is used to access members of a class in C++? Question 1
  • 9. 1. int main() 2. void main() 3. None 4. Both 1 and 2 Which of the following is the correct implementation / use of main() function? Question 2
  • 10. 1. int main() Which of the following operators is used to access members of a class in C++? Question 2
  • 11. 1. The program has encountered an error. 2. The program has executed successfully. 3. It has no specific meaning. 4. It causes the program to terminate immediately. What does return 0; signify in the main function? Question 3
  • 12. The program has executed successfully. What does return 0; signify in the main function? Question 3
  • 13. 1. The main function can only create instances of classes. 2. The main function cannot use class methods. 3. The main function can access static members of classes directly. 4. The main function must be defined within a class. Which of the following statements is true regarding the use of the main function in object-oriented programming? Question 4
  • 14. The main function can access static members of classes directly Which of the following statements is true regarding the use of the main function in object-oriented programming? Question 4
  • 15. A. The function continues to execute any remaining statements after the return. B. The function exits immediately, and control is passed back to the calling function. C. The function returns control to the main function. D. The function throws an exception. In C++, what happens when a return statement is encountered in a function? Question 5
  • 16. The function exits immediately, and control is passed back to the calling function. In C++, what happens when a return statement is encountered in a function? Question 5
  • 17. A. The return statement can be used to return a value from a function. B. A void function can have a return statement without any value. C. If a function returns void, it cannot have a return statement. D. When a return statement is executed, the function terminates immediately. Which of the following statements about the return statement in C++ is false? Question 6
  • 18. If a function returns void, it cannot have a return statement. Which of the following statements about the return statement in C++ is false? Question 6
  • 19. A) Only the constructor B) Only the destructor C) Both constructor and destructor D) Copy constructor and assignment operator If a class has dynamically allocated memory, which of the following should be implemented? Question 6
  • 20. Copy constructor and assignment operator Which of the following statements about the return statement in C++ is false? Question 6
  • 21. A) All statements are Valid. B) A derived class can override the constructor of a virtually inherited class. Which of the following statements is NOT valid in the context of virtual inheritance in C++? Question 7 C) A virtually inherited base class's constructor is called only once, regardless of how many derived classes inherit it. D) In virtual inheritance, the most derived class is responsible for initializing the virtually inherited base class.
  • 22. A derived class can override the constructor of a virtually inherited class. Which of the following statements is NOT valid in the context of virtual inheritance in C++? Question 7
  • 23. MCQ True False Questions Fill in the Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
  • 24. MCQ True False Questions Fill in the Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
  • 26. Question 1 Friend functions can be inherited by derived classes. TRUE FALSE
  • 27. Question 1 Friend functions can be inherited by derived classes. TRUE FALSE
  • 28. Question 2 The scope of a variable declared inside a function in C++ is Class scope. TRUE FALSE
  • 29. Question 2 The scope of a variable declared inside a function in C++ is Class scope. TRUE FALSE
  • 30. Question 3 The size of int data type is always 4 bytes, irrespective of the system architecture. TRUE FALSE
  • 31. Question 3 The size of int data type is always 4 bytes, irrespective of the system architecture. TRUE FALSE
  • 32. MCQ True False Questions Fill in the Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
  • 33. MCQ True False Questions Fill in the Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
  • 35. Question 1 In a class, a static member function can only access ______ data members of the class, because it does not have access to the ______ pointer.
  • 36. Question 1 In a class, a static member function can only access ______ data members of the class, because it does not have access to the ______ pointer. 1. static 2. this
  • 37. Question 2 To call a static member function multiply from a class named MathOperations, you can write MathOperations::multiply(4, 5);. This syntax is possible because multiply is associated with the ____ itself, not with any specific ____.
  • 38. Question 2 To call a static member function multiply from a class named MathOperations, you can write MathOperations::multiply(4, 5);. This syntax is possible because multiply is associated with the ____ itself, not with any specific ____. 1. Class 2. Object
  • 39. Question 3 In C++, the operator ___ cannot be overloaded. (Choose one: ::, ++, +, -)
  • 40. Question 3 In C++, the operator ___ cannot be overloaded. (Choose one: ::, ++, +, -) ::
  • 41. Question 4 In C++, the operator ___ cannot be overloaded. (Choose one: ::, ++, +, -)
  • 42. Question 4 In C++, the operator ___ cannot be overloaded. (Choose one: ::, ++, +, -) ::
  • 43. Question 5 When overloading an operator as a member function, the left-hand operand is always __________.
  • 44. Question 5 When overloading an operator as a member function, the left-hand operand is always __________. this
  • 45. MCQ True False Questions Fill in the Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
  • 46. MCQ True False Questions Fill in the Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
  • 48. Static member functions cannot be virtual. Static member functions are associated with the class, not with specific instances of the class. ASSERTION REASON A false, R true A true, R false Both False Both True Question 1
  • 49. Static member functions cannot be virtual. Static member functions are associated with the class, not with specific instances of the class. ASSERTION REASON A false, R true A true, R false Both False Both True Question 1
  • 50. Destructors can have return types in C++. Destructors must return void because they are automatically called by the system and are not meant to return values. ASSERTION REASON Both True A false, R true A true, R false Both False Question 2
  • 51. Destructors can have return types in C++. Destructors must return void because they are automatically called by the system and are not meant to return values. ASSERTION REASON Both True A false, R true A true, R false Both False Question 2
  • 52. MCQ True False Questions Fill in the Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
  • 53. MCQ True False Questions Fill in the Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
  • 55. 55 int x = 5; x = x+++++x; Find the output by analyzing the code. Question 1
  • 56. 56 int x = 5; x = x+++++x; Find the output by analyzing the code. Answer: Undefined behavior Question 1
  • 57. 57 Find the output by analyzing the code. class Test { public: int x; Test(int value) : x(value) { cout << "Constructor called for x = " << x << endl; } ~Test() { cout << "Destructor called for x = " << x << endl; } }; int main() { Test t1(10); { Test t2(20); } cout << "End of main" << endl; return 0; } Question 2
  • 58. 58 Find the output by analyzing the code. class Test { public: int x; Test(int value) : x(value) { cout << "Constructor called for x = " << x << endl; } ~Test() { cout << "Destructor called for x = " << x << endl; } }; int main() { Test t1(10); { Test t2(20); } cout << "End of main" << endl; return 0; } Ans: Constructor called for x = 10 Constructor called for x = 20 Destructor called for x = 20 End of main Destructor called for x = 10 Question 2
  • 59. 59 Find the output by analyzing the code. class MyClass { int* ptr; public: MyClass(int size) { ptr = new int[size]; // Dynamically allocate memory cout << "Memory allocated for " << size << " integers." << endl; } ~MyClass() { delete[] ptr; // Deallocate memory cout << "Memory deallocated." << endl; } }; int main() { MyClass obj(5); // Dynamically allocate memory for 5 integers return 0; } Question 3
  • 60. 60 Find the output by analyzing the code. class MyClass { int* ptr; public: MyClass(int size) { ptr = new int[size]; // Dynamically allocate memory cout << "Memory allocated for " << size << " integers." << endl; } ~MyClass() { delete[] ptr; // Deallocate memory cout << "Memory deallocated." << endl; } }; int main() { MyClass obj(5); // Dynamically allocate memory for 5 integers return 0; } Answer: The output will be: Memory allocated for 5 integers. Memory deallocated. Question 3
  • 61. 61 Find the output by analyzing the code. class Complex { public: int real, imag; Complex(int r, int i) : real(r), imag(i) {} Complex operator*(const Complex& c) { return Complex(real * c.real - imag * c.imag, real * c.imag + imag * c.real); } void display() { cout << real << "+" << imag << "i "; } }; int main() { Complex c1(2, 3), c2(4, 5); Complex c3 = c1 * c2; c3.display(); return 0; } Question 4
  • 62. 62 Find the output by analyzing the code. class Complex { public: int real, imag; Complex(int r, int i) : real(r), imag(i) {} Complex operator*(const Complex& c) { return Complex(real * c.real - imag * c.imag, real * c.imag + imag * c.real); } void display() { cout << real << "+" << imag << "i "; } }; int main() { Complex c1(2, 3), c2(4, 5); Complex c3 = c1 * c2; c3.display(); return 0; } Answer: -7+22i Question 4