I am reading a book and there is a chapter about pointers. I have grasp the main idead of a pointer which hold the memory address of another variable or object. But, later, in the book, is says that all these local variables are destroyed after the function call. Ok, I already knew that. Also it says that a way to fix that is using global variables stored in namespace or use pointers to store the data in heap section .
Could you tell me why I should want to use heap section instead of stack section ?
If the problem is the destroyed data after return, I think that I can bypass this problem using parameters instead of using pointers in order to store the data in heap section. The parameters are not destroyed, right ?