Please tell me in the following question why no copy constructor is called when fun returns the A object.
While returning b and constructing c, there is no copy constructor called. Why??
using namespace std;
A fun(A a)
A c = a.fun(a); // Here atleast copy copy constructor should have been called.
This is a case of return-value-optimization (or RVO). This is one of the few cases (with copy elision) where the compiler is allowed to change the behavior of the code (by eliminating calls to copy constructors and destructors) for optimization purposes. In other words, never depend on a specific number of copies being created as part of the critical behavior of your program.