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
  • Conversion Operators

C++ Programming

CONVERSION OPERATORS MCQs

Total Questions : 10

Question 1.

Pick out the correct syntax of operator conversion.


  1.    operator float()const
  2.    operator float()const
  3.    operator const
  4.    None of the mentioned
 Discuss Question
Answer is Option A. -> operator float()const

None.

Question 2.

How types are there in user defined conversion?


  1.    1
  2.    2
  3.    3
  4.    4
 Discuss Question
Answer is Option B. -> 2

There are two types of user-defined conversions.They are conversion by constructor, 

Conversion functions.

Question 3.


What is the output of this program?



1.
#include
2.
using namespace std;
3.
int main()
4.
{
5.
double a = 21.09399;
6.
float b = 10.20;
7.
int c ;
8.
c = (int) a;
9.
cout
  1.    2110
  2.    1210
  3.    21
  4.    None of the mentioned
 Discuss Question
Answer is Option A. -> 2110

In this program, we casted the data type to integer.
Output:
$ g++ con5.cpp
$ a.out
2110

Question 4.


What is the output of this program?



1.
#include
2.
#include
3.
using namespace std;
4.
class test
5.
{
6.
public:
7.
operator string ()
8.
{
9.
return "Converted";
10.
}
11.
};
12.
int main()
13.
{
14.
test t;
15.
string s = t;
16.
cout
  1.    converted
  2.    error
  3.    run time error
  4.    None of the mentioned
 Discuss Question
Answer is Option A. -> converted

In this program, We casted the string to the object of the class.
Output:
$ g++ con4.cppp
$ a.out
converted

Question 5.


What is the output of this program?



1.
#include
2.
#include
3.
using namespace std;
4.
class Complex
5.
{
6.
private:
7.
double real;
8.
double imag;
9.
public:
10.
Complex(double r = 0.0, double i = 0.0) : real(r), imag(i)
11.
{}
12.
double mag()
13.
{
14.
return getMag();
15.
}
16.
operator double ()
17.
{
18.
return getMag();
19.
}
20.
private:
21.
double getMag()
22.
{
23.
return sqrt(real * real + imag * imag);
24.
}
25.
};
26.
int main()
27.
{
28.
Complex com(3.0, 4.0);
29.
cout
  1.    5 5
  2.    4 5
  3.    6 6
  4.    None of the mentioned
 Discuss Question
Answer is Option A. -> 5 5

In this program, we are calculating the magnitude value by two ways.
Output:
$ g++ con3.cpp
$ a.out
55

Question 6.


What is the output of this program?



1.
#include
2.
using namespace std;
3.
class sample
4.
{
5.
public:
6.
sample(int i) : m_i(i) { }
7.
public:
8.
int operator()(int i = 0) const
9.
{
10.
return m_i + i;
11.
}
12.
operator int () const
13.
{
14.
return m_i;
15.
}
16.
private:
17.
int m_i;
18.
friend int g(const sample&);
19.
};
20.
int f(char c)
21.
{
22.
return c;
23.
}
24.
int main()
25.
{
26.
sample f(2);
27.
cout
  1.    3
  2.    4
  3.    5
  4.    None of the mentioned
 Discuss Question
Answer is Option B. -> 4

In this program, we are adding its value with it itself, So only we got the output as 4.
Output:
$ g++ con1.cpp
$ a.out
4

Question 7.

How many parameters does a conversion operator may take?


  1.    0
  2.    1
  3.    2
  4.    as many as possible
 Discuss Question
Answer is Option A. -> 0

None.

Question 8.


What is the output of this program?



1.
#include
2.
using namespace std;
3.
class sample1
4.
{
5.
float i, j;
6.
};
7.
class sample2
8.
{
9.
int x, y;
10.
public:
11.
sample2 (int a, int b)
12.
{
13.
x = a;
14.
y = b;
15.
}
16.
int result()
17.
{
18.
return x + y;
19.
}
20.
};
21.
int main ()
22.
{
23.
sample1 d;
24.
sample2 * padd;
25.
padd = (sample2*) &d;
26.
cout < result();
27.
return 0;
28.
}

  1.    20
  2.    runtime error
  3.    random number
  4.    c or b
 Discuss Question
Answer is Option D. -> c or b

As it assigns to a reference to an object of another incompatible type using explicit type-casting.
Output:
$ g++ con.cpp
$ a.out
14032334

Question 9.

Why we use the "dynamic_cast" type conversion?



  1.    result of the type conversion is a valid
  2.    result of the type conversion is a valid
  3.    result of the type conversion is a invalid
  4.    None of the mentioned
 Discuss Question
Answer is Option A. -> result of the type conversion is a valid

It is used to check that operators and operands are compatible after conversion.

Question 10.

What is the return type of the conversion operator?


  1.    void
  2.    int
  3.    float
  4.    no return type
 Discuss Question
Answer is Option D. -> no return type

Conversion operator doesn't have any return type not even void.

  • 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

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)
  • 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

Recent Questions

Q.   Apache Bigtop Uses ___________ For Continuous Integration T....

Q.   Corporates Have Benefited Tremendously 1)/ From The Governme....

Q.   A Little Gush Of Gratitude

Q.   Among The Following Which Layer Is Directly Apposed To The C....

Q.   Metal Chloride That Is Hydrated Is

Q.   A Steel Member Used In The Furnace Construction To Take The ....

Q.   Which Of The Following Is not Among The Advantages Of H....

Q.   He Killed The Enemy By His Sword.

Q.   Main Circuit Board In A Computer Is...

Q.   The Interpreter Of Indian Constitution Is-

Q.   Rectify

Q.   How Many 4d Orbitals Are There In An Atom?

Q.   If You Increase The Mass On An Object, Its Acceleration

Q.   Which Of The Following Is Capable Of Oxidizing Sulfur To Sul....

Q.   An....

Q.   India's First Private Sector Rocket Vikram-S, Was Developed ....

Q.   Rover Weighs Less Than Fido. Rover Weighs More Than Boomer. ....

Q.   A Cross Shaped (+) Or A Ring Involving Four Chromosomes May ....

Q.   Priming Is Needed In A __________ Pump.

Q.   Dynamic Similarity Is Said To Exist Between The Model And Th....

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
  • YouTube Channel
  • Maths Fast Trick
  • 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