c++ Expression exercise

C++ exercise

1. What is the return type of the conversion operator ?

a. int
b. float
c. no return type
d. void

Show Answer

The correct option is (b)
c Explanation:
The Conversion operator doesn’t have any return type not even void..

2. How many parameters does a conversion operator may take ?

a. 0
b. 1
c. 2
d. Many As Possible

Show Answer

The correct option is (a)
Explanation:
0(zero) parameters does a conversion operator will take.

3. What will be the output of the following C++ code?

#include < iostream >
using namespace std;
class Test1
{
float l, m;
};
class Test2
{
int x, y;
public:
Test2 (int a, int b)
{
x = a;
y = b;
} int result() { return x + y; }
};
int main ()
{
Test1 t1;
Test2 * padd;
padd = (Test2*) &t1;
cout<< padd->result();
return 0;
}

a. runtime error
b. random number
c. runtime error or random number
d. 10

Show Answer

The correct option is (c)
Explanation:
As it assigns to a reference to an object of another incompatible type using explicit type-casting.

4. How are types therein user-defined conversion ?

a. 1
b. 2
c. 3
d. 4

Show Answer

The correct option is (b)
Explanation:
So There are two types of user-defined conversions. They are conversion by the constructor, Conversion functions.

5. What will be the output of the following C++ code?

#include < iostream >
using namespace std;
int main()
{
double x = 25.09399;
float y = 10.50;
int c ;
c = (int) x;
cout << c ;
c = (int) y;
cout << c ;
return 0;
}

a. 2510
b. 1210
c. 1234
d. 120

Show Answer

The correct option is (a)
Explanation:
In this program, we casted the data type to integer.

6. What is the type casting ?

a. Convert one function into another.
b. Convert one data type into another.
c. Convert operator into another type
d. None of them

Show Answer

The correct option is (b)
Explanation:
No Explanation

7. A virtual member function is a member function that can be ?

a. Be Overriding by subclass.
b. Be derived from another class.
c. Move to another class
d. None of them

Show Answer

The correct option is (a)
Explanation:
No Explanation

8. Pick out the correct syntax of operator conversion ?

a. operator float()
b. operator const
c. operator float()const
d. operator const()

Show Answer

The correct option is (c)
Explanation:
The syntax of operator conversion is operator float()const.

8. What are the escape sequences ?

a. Set of characters that whose use are avoided in C++ programs
b. Set of characters that are used in the name of the main function of the program
c. Set of characters that convey special meaning in a program
d. Set of characters that are avoided in cout statements

Show Answer

The correct option is (c)
Explanation:
Escape sequence is a set of characters that convey a special meaning to the program. They are used to convey a meaning which cannot be conveyed directly.

  • C++ Dynamic Initialization of Objects
  • C++ Copy Constructor
  • C++ Dynamic Constructor
  • C++ Destructors
  • C++ Exercise
  • C++ Operator Overloading
  • C++ Overloading Unary Operators
  • Const pointer in C
  • Void pointer in c
  • C++ Overloading Binary Operators
  • C++ Overloading Binary Operators Using Friends
  • C++ Manipulation String Using Operators
  • C++ Rules for overloading operators
  • C++ Exercise
  • C++ Basic To class Type
  • C++ Class TO Basic Type
  • C++ One class To another class type
  • C++ Exercise
  • C++ Inheritance introduction
  • C++ Single Inheritance
  • C++ Multiple Inheritance
  • C++ Ambiguity Resolution in inheritance
  • C++ Hierarchical Inheritance
  • C++ Hybrid Inheritance
  • C++ Virtual Base Classes
  • C++ Exercise
  • C++ abstract class
  • C++ nesting of classes
  • C++ Exercise
  • C++ polymorphism
  • C++ Exercise
  • C++ pointers
  • C++ Pointers TO object
  • C++ this pointer
  • C++ Pointer to Derived class
  • C++ Virtual functions
  • C++ Exercise
  • C++ streams
  • C++ unformatted I/O operations
  • C++ Put() and get()
  • C++ getline() and write()
  • C++ Formatted console I/O
  • C++ Manipulators
  • C++ Exercise
  • C++ file handling
  • C++ file stream classes
  • C++ Open and closing file
  • C++ open using constructor
  • C++ open using open()
  • C++ Detecting End of file
  • C++ File modes
  • C++ File pointers and Manipulators
  • C++ Sequential I/O
  • C++ Reading and Writing
  • C++ Updating a File
  • C++ Error handling In File
  • C++ Command Line Arguments
  • C++ Exercise
  • C++ Template introduction
  • C++ Class Templates with multiple Parameters
  • C++ Function templates
  • C++ Function templates with multiple parameters
  • C++ member function Template
  • C++ Exercise
  • C++ Exception handling
  • C++ Basics of Exception Handling
  • C++ Exception Handling Mechanism
  • C++ Throwing Mechanism
  • C++ Catch Mechanism
  • C++ Catch all Exceptions
  • C++ Re-Throwing An Exception
  • C++ Specifying Exceptions
  • C++ Exercise