Use the stack when your variable will not be used after the current function returns. Use the heap when the data in the variable is needed beyond the lifetime of the current function.
More Related Contents:
- cin and getline skipping input [duplicate]
- Uses of C comma operator [duplicate]
- C++ std::set update is tedious: I can’t change an element in place
- Deploying Qt 5 App on Windows
- Why SDL defines main macro?
- Function with missing return value, behavior at runtime
- ‘size_t’ vs ‘container::size_type’
- how do I print an unsigned char as hex in c++ using ostream?
- difference between a pointer and reference parameter?
- Object creation on the stack/heap?
- Why are NULL pointers defined differently in C and C++?
- How to set file permissions (cross platform) in C++?
- What happens to the pointer itself after delete? [duplicate]
- Which Boost features overlap with C++11?
- Now that we have std::array what uses are left for C-style arrays?
- C++ int to byte array
- Reason for C++ member function hiding [duplicate]
- Difference between using #include and #include in C++
- Why does nvcc fails to compile a CUDA file with boost::spirit?
- What happens when I assign a number larger than INT_MAX to an int?
- C++ convert vector to vector
- std::fstream buffering vs manual buffering (why 10x gain with manual buffering)?
- What is going on with bitwise operators and integer promotion?
- Why do some experienced programmers write comparisons with the value before the variable? [duplicate]
- C++ terminate called without an active exception
- What does int() do in C++?
- Where should non-member operator overloads be placed?
- Why would I std::move an std::shared_ptr?
- difference between pointer to an array and pointer to the first element of an array
- Wrapping FILE* with custom std::ostream