LakshyaEducation.in

VEDIC MATHS Video Series
  • Home
  • Video Series
    • Vedic Maths Videos
    • Quantitative Aptitude Videos
    • Class 8 Maths Videos
    • Class 9 Maths Videos
    • Class 10 Maths Videos
  • Quiz & Solutions
  • Blog
  • Store
  • Login
  • Contact Us
  • Home
  • Topic
  • C++ Programming
  • Exceptions And Efficiency

C++ Programming

EXCEPTIONS AND EFFICIENCY MCQs

Total Questions : 10

Question 1.

Why is it expensive to use objects for exception?


  1.    Exception object is created only if an error actually happens
  2.    Because of execution time
  3.    Memory space involved in creating an exception object
  4.    None of the mentioned
 Discuss Question
Answer is Option A. -> Exception object is created only if an error actually happens

If an error occurs in program, then only exception object is created otherwise, It will not be 

created. So it's expensive to use in the program.

Question 2.

What is the main purpose of the constructor?


  1.    Begin the execution of the class
  2.    Include the macros for the program
  3.    Establish the class invariant
  4.    None of the mentioned
 Discuss Question
Answer is Option C. -> Establish the class invariant

The purpose of a constructor is to establish the class invariant. To do that, it often needs to 

acquire system resources or in general perform an operation that may fail.

Question 3.


What is the output of this program?



1.
#include
2.
using namespace std;
3.
double division(int a, int b)
4.
{
5.
if (b == 0)
6.
{
7.
throw "Division by zero condition!";
8.
}
9.
return (a / b);
10.
}
11.
int main ()
12.
{
13.
int x = 50;
14.
int y = 0;
15.
double z = 0;
16.
try
17.
{
18.
z = division(x, y);
19.
cout
  1.    50
  2.    0
  3.    Division by zero condition
  4.    Error
 Discuss Question
Answer is Option D. -> Error

As we missed the data type in the catch block, It will arise an error.

Question 4.


What is the output of this program?



1.
#include
2.
#include
3.
using namespace std;
4.
int main ()
5.
{
6.
int num = 3;
7.
string str_bad = "wrong number used";
8.
try
9.
{
10.
if ( num == 1 )
11.
{
12.
throw 5;
13.
}
14.
if ( num == 2 )
15.
{
16.
throw 1.1f;
17.
}
18.
if ( num != 1 || num != 2 )
19.
{
20.
throw str_bad;
21.
}
22.
}
23.
catch (int a)
24.
{
25.
cout
  1.    Exception is 5
  2.    Exception is 1.1f
  3.    wrong number used
  4.    None of the mentioned
 Discuss Question
Answer is Option C. -> wrong number used

As we are giving 3 to num, It is arising an exception named
"wrong number used".
Output:
$ g++ expef.cpp
$ a.out
wrong number used

Question 5.


What is the output of this program?



1.
#include
2.
#include
3.
#include
4.
using namespace std;
5.
void func(int c)
6.
{
7.
if (c < numeric_limits :: max())
8.
throw invalid_argument("MyFunc argument too large.");
9.
else
10.
{
11.
cout
  1.    Invalid arguments
  2.    Executed
  3.    Error
  4.    Runtime error
 Discuss Question
Answer is Option B. -> Executed

As we are throwing the function and catching it with a correct data type, So this program will execute.
Output:
$ g++ expef.cpp
$ a.out
Executed

Question 6.


What is the output of this program?



1.
#include
2.
using namespace std;
3.
void test(int x)
4.
{
5.
try
6.
{
7.
if (x > 0)
8.
throw x;
9.
else
10.
throw 'x';
11.
}
12.
catch(char)
13.
{
14.
cout
  1.    Catch a integer and that integer is:10
  2.    Error
  3.    Runtime error
  4.    None of the mentioned
 Discuss Question
Answer is Option C. -> Runtime error

As the catch is created with a wrong type, So it will
arise a runtime error.
Output:
$ g++ expef.cpp
$ a.out
Testing multiple catches
terminate called after throwing an instance of /int'
:Aborted

Question 7.

What operation can be performed by destructor?


  1.    Abort the program
  2.    Resource cleanup
  3.    Exit from the current block
  4.    None of the mentioned
 Discuss Question
Answer is Option B. -> Resource cleanup

It will be used to free all the resources that are used by block of code during execution.

Question 8.


What is the output of this program?



1.
#include
2.
#include
3.
using namespace std;
4.
int main ()
5.
{
6.
try
7.
{
8.
double* i= new double[1000];
9.
cout
  1.    Memory allocated
  2.    Exception arised
  3.    Depends on the computer memory
  4.    None of the mentioned
 Discuss Question
Answer is Option C. -> Depends on the computer memory

The value will be allocated, if there is enough memory in the system.
Output:
$ g++ expef.cpp
$ a.out
Memory allocated

Question 9.

What will happen when we move try block far away from catch block?


  1.    Reduces the amount of code in cache
  2.    Increases the amount of code in cache
  3.    Don't alter anything
  4.    None of the mentioned
 Discuss Question
Answer is Option A. -> Reduces the amount of code in cache

compilers may try to move the catch-code far away from the try-code, which reduces the 

amount of code to keep in cache normally, thus enhancing performance.

Question 10.

What will happen if an excpetion that is thrown may causes a whole load of objects to go out of scope?


  1.    Terminate the program
  2.    Produce a runtime error
  3.    It will be added to the overhead
  4.    None of the mentioned
 Discuss Question
Answer is Option C. -> It will be added to the overhead

None.

  • Share on Facebook!
  • Share on Pinterest!

Sub Topics

  • Abstract Classes
  • Access Control
  • Argument Passing
  • Arrays
  • Booleans
  • C++ Concepts
  • Catching Exceptions
  • Character Types
  • Class Hierarchies And Abstract Classes
  • Class Hierarchies Introduction
  • Classes
  • Comments And Indentation
  • Complex Number Type
  • Constants
  • Constructors And Destructors
  • Container Design
  • Conversion Operators
  • Declaration
  • Default Arguments
  • Dereferencing
  • Derivation And Templates
  • Derived Classes
  • Design Of Class Hierarchies
  • Enumerations
  • Error Handling
  • Error Handling Alternatives
  • Essential Operators
  • Exception Specifications
  • Exceptions
  • Exceptions And Efficiency
  • Exceptions That Are Not Errors
  • Floating Point Types
  • Free Store
  • Friends
  • Function Call
  • Function Declarations
  • Function Templates
  • Functions
  • Grouping Of Exceptions
  • Header Files Usage
  • Increment And Decrement
  • Integer Types
  • Large Objects
  • Linkage
  • Macros
  • Modularization And Interfaces
  • Multiple Inheritance
  • Namespaces
  • Objects
  • Objects And Classes
  • Oops Concepts
  • Operator Functions
  • Operators
  • Overloaded Function Names
  • Pointer To Function
  • Pointer To Void
  • Pointers
  • Pointers Into Arrays
  • Pointers To Members
  • References
  • Resource Management
  • Run Time Type Information
  • Sequence Adapters
  • Sequences
  • Simple String Template
  • Sizes
  • Specialization
  • Standard Exceptions
  • Standard Library Design
  • Statements
  • String Class
  • Structures
  • Subscripting
  • Template Arguments To Specify Policy Usage
  • Types
  • Uncaught Exceptions
  • Unspecified Number Of Arguments
  • User Defined Types
  • Value Return
  • Vector
  • Void

Recent Posts

  • Sail E0 Results 2022
  • Is Ssc Difficult Than Upsc?
  • Quantitative Aptitude Faqs
  • Vedic Maths Faq
  • Ssc Exam Guide Book
  • Sail E0 Exam Results Cancelled - Exam Will Be Rescheduled
  • Best Ssc Exam For Girls

Recent Questions

Q.   Which Of The Following Methods Can Be Used For Manufacturing....

Q.   Bromine Is A

Q.   The Branch Current Method Is Based On Kirchhoff's Voltage La....

Q.   Which Is The Shortcut Key To Jump To The First Slide Of The ....

Q.   The Earliest Known Epigraphic Evidence Of Bhagvatism Is

Q.    the Average Of First 10 Odd Numbers Is?

Q.   Who Was The Architect Who Designed "Taj Mahal" ?

Q.   Antonym Of Supernal ?

Q.   The Arranging Of Data In A Logical Sequence Is Called

Q.   Gopal Krishna Gokhale

Q.   After You Wet Your Hands You Should Apply ______ And _____ F....

Q.   The Practical Limit Of Moisture Content Achieved In Air Dryi....

Q.   The Sieder-Tate Correlation For Heat Transfer In Turbulent F....

Q.   Which Of The Following Is Not A Measure Of Product Deficienc....

Q.   After Choosing A Predefined Template, Which Option Has To Be....

Q.   Who Has Won The Best Actor Award At The 67th National Awards....

Q.   The Rails Get Out Of Their Original Positions Due To Insuffi....

Q.   The Unit Of Pressure Most Commonly Found On A Surface Weathe....

Q.   The Charging Time Constant Of A Circuit Consisting Of An Ind....

Q.   Which Of Following Is First Sign Of Colorectal Cancer?

Topics

Computer Aptitude
SAIL Junior Officer (E-0)
10th Grade
11th Grade
12th Grade
4th Grade
5th Grade
6th Grade
7th Grade
8th Grade
9th Grade
NCERT
Cat
Commerce
Computer Science
Engineering
English
General Knowledge
Ias
Management
Quantitative Aptitude
Reasoning Aptitude
General Studies (Finance And Economics)
Vedic Maths
Analytical Instrumentation
Biochemistry
Bioinformatics
Biology
Biotechnology
Bitsat
Business Statistics
C Programming
C++ Programming
Cell Biology
Chemistry
Cost Accounting
Drug And Pharmaceutical Biotechnology
Electrical Measurement And Instrumentation
Environment Management
Environmental Biotechnology
Enzyme Technology
Financial Management And Financial Markets
Gate
General Science
Geography
Heat Transfer
History And National Movements
Human Anatomy And Physiology
Human And Cultural Diversity
Human Resource Management
Indian Economy
Indian Geography
Indian History
Indian Polity
Instrumentation Transducers
International Relations
Life Sciences
Marketing And Marketing Management
Mass Transfer
Mechanics Of Materials
Microbiology
Neet
Professional Communication
Renewable Energy
Sociology
Surveying
Total Quality Management
Uidai Aadhaar Supervisor Certification
Virology
LakshyaEducation.in
Lakshya Education
Bhilai,Chattisgarh,India
Email: admin@lakshyaeducation.in Phone: 07893519977 (WhatsApp)

Quick Links

  • Vedic Maths
  • Quantitative Aptitude
  • Class – IX Maths
  • Class – X Maths
  • Blog

Our Services

  • About us
  • Privacy
  • TOS
  • Refund / Cancellation
  • Contact
  • Affiliate Program
  • Copyright © 2022 All Right Reserved | Lakshya Education     ( )
    Login / Register

    Your Account will be created automatically when you click the below Google or Facebook Login Button.
    •   Login With Facebook
    •  Login With Google
     Login With Email/Password