cpp type conversion Exercise

C++ exercise

1. Which header file do you need to include to use typecasting ?

a. stdin.h.
b. ctype.h
c. math.h
d. None.

Show Answer

The correct option is (d)
Explanation:
No explanation found for this Question

2. Which is a valid typecast ?

a. char:a;.
b. a(char);.
c. to(char, a);
d. (char)a;

Show Answer

The correct option is (d)
Explanation:
No explanation found for this Question.

3. Which conversion is not possible?

a. int to float
b. float to int
c. char to float
d. All are possible

Show Answer

The correct option is (d)
Explanation:
No Explanation

4. In C++ what type of operator is a cast operator?

a. Unary
b. Ternary
c. Binary
d. Quaternary

Show Answer

The correct option is (a)
Explanation:
The cast operator is a unary operator which is used to convert one data type into another forcefully.

5. What is the conversion type for reinterpret casting ?

a. Pointer to Variable
b. Pointer to Pointer
c. Variable to Pointer
d. Variable to Variable

Show Answer

The correct option is (b)
Explanation:
Reinterpret casting is used to convert a pointer of any data type to another pointer of any other data type. Additionally, this does not match the datatype of the value and the pointer.

6. const_cast manipulates the constness of an object, either to be set or to be removed ?

a. True
b. False

Show Answer

The correct option is (a)
Explanation:
Explanation not found

7. How many type of conversion are there in c?

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

Show Answer

The correct option is (b)
Explanation:
Basically 2 types of convsersion : Implicit Type Conversion and Explicit Type Conversion.

8. Which conversion also called Automatic Type Conversion?

a. Implicit Type Conversion.
b. Both A and B
c. Explicit Type Conversion
d. None of the above

Show Answer

The correct option is (a)
Explanation:
This type of conversion is usually performed by the compiler when necessary without any commands by the user. Thus it is also called “Automatic Type Conversion”.

9. Which type of conversion is NOT accepted ?

a. From float to char pointer
b. From negative int to char
c. From double to char
d. From char to int

Show Answer

The correct option is (a)
Explanation:
Conversion of a float to pointer type is not allowed.

10. Which of the following typecasting is accepted by C?

a. Narrowing conversions
b. Widening & Narrowing conversions
c. Widening conversions
d. None of the above

Show Answer

The correct option is (b)
Explanation:
Widening & Narrowing conversions following typecasting is accepted by C.

  • 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