What is the output of the following snippet?

Last Updated on May 3, 2022 by Admin 2

What is the output of the following snippet?

#include <iostream>
using namespace std;

class A {
public:
    float v;
    float set(float v) {
       v += 1.0;
       this -> v = v;
       return v;
    }
    float get(float d) {
       v += 1.0;
       return v;
    }
};

int main()
{
    A a;  
    cout << a.get(a.set(a.set(0.5)));
    return 0;
}
  • 3.5
  • 1.5
  • Compilation fails
  • 2.5
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments