Hello.
I have a general question regarding constructors and memory.
As I believe, when you compile and run a program a certain amount of memory is put aside for the program and all the variables and content of that program correct?
Today I was taught that I should always initialize my content with a constructor. We exercised this through a program creating and manipulating fractions.
Default constructor
Overloaded constructorCode:Fraction () {init(0,1)};
Today I was taught that we need a default constructor and an overloaded constructor.Code:Fraction(int n, int d){init(n,d);}
Now my question that I missed out on asking during the lecture was, why exactly do we need a default constructor to initialize?
I thought that it is not really needed because compiling and running a program will set aside "clean memory" for that process.
I was told that if we did not, than garbage (junk memory) would be contained in those variable slots? Correct?
Am I confusing myself here?
I would appreciate any feedback to guide me in understanding this new concept
Thanks in advance.