I am kind of getting bogged down by the concept of memory management (all my previous programming languages doesn't need me to manage the memory). I'm not sure if creating a variable will consume memory if I don't destroy it later.
#include <math.h>
#include <iostream>
using namespace std;
double sumInfiniteSeries(double u1, double r){
return u1 / (1 - r);
}
double sumInfiniteSeries(double u1, double r, bool printSteps){
if (printSteps){
double lastTotal;
double total = 0.0;
double sn = u1;
for (int n=1;n<=1000;n++){
lastTotal = total;
total += sn;
sn *= r;
cout << "n = " << n << ": " << total << endl;
if (fabs(lastTotal - total) < 0.000000000000001) return total;
}
return total;
} else {
return sumInfiniteSeries(u1, r);
}
}
Do i need to "destroy" any variables in these 2 functions?
Edit: So when I create my own class and its instance would I need to start memory management?