title: What happens when an object is assigned to a value in c++
body: <p>Check the following code:</p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  
  class example
  {
      public:
      int number;
  
      example()
      {
          cout&lt;&lt;"1";
          number = 1;
      }
  
      example(int value)
      {
          cout&lt;&lt;"2";
          number = value;
      }
  
      int getNumber()
      {
          cout&lt;&lt;"3";
          return number;
      }
  };
  
  int main()
  {
      example e;
      e = 10;
      cout&lt;&lt;e.getNumber();
      return 0;
  }
  </code></pre>
  
  <p>What is the output of the above code. Also, I want to know what happens when an object is directly assigned to a value. How will the compiler interpret it?</p>