Hi,
I have a few questions regarding memory handling in C++.
What's the different with
Mystruct *s = new Mystruct
andMystruct s
? What happens in the memory?Looking at this code:
struct MyStruct{ int i; float f; }; MyStruct *create(){ MyStruct tmp; tmp.i = 1337; tmp.j = .5f; return &tmp; } int main(){ MyStruct *s = create(); cout << s->i;
}return 0;
When is MyStruct tmp
free'd?
Why doesn't MyStruct tmp
get automatically free'd in the end of create()
?
Thank you!