Home » C++ Programming » Operators » Question
  1. What is the output of this program?
    #include <iostream>
    #include <string>
    using namespace std;
    class Example
    {
    public:
    operator string ()
    {
    return "Converted...";
    }
    };
    int main()
    {
    Example examp;
    string str = examp;
    cout << str << endl;
    return 0;
    }
    1. Compilation Error
    2. Runtime Error
    3. Converted...
    4. Garbage value
    5. None of these
Correct Option: C

In this program, We casted the string to the object of the class.



Your comments will be displayed only after manual approval.