Coming from a Java background, I'm trying to learn how to handle memory (de)allocation in C/C++ in the simplest way.
A colleague suggested that I only allocate memory for member variables and let the stack handle the local variables. I'm not entirely sure what this concept is called, but it means that functions would be implemented like this:
void inc(int x, int &y){
y=x+1;
}
Another way would be this:
int inc(int x, int &y){
y=x+1;
return y;
}
First one prohibits me from using it in an expression, i.e:
int y;
inc(2,y);
inc(y,y);
Second one does, but it isn't pretty:
int y;
y=inc(inc(2,y),y);
Before I go mess up my code, what do seasoned C/C++ programmers think about this coding style?