Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
void func() { const int intAge = 24; }
intAge跑步后会发生什么func()?您是否必须释放它,或者 C++ 编译器是否这样做?
intAge
func()
当变量超出范围时,具有自动存储持续时间的变量的存储会自动释放。这由语言实现处理。
事实上,没有必要也没有办法手动释放任何变量的内存。只有动态内存可以手动释放。
不,内存是使用堆栈内存分配的,堆栈内存在作用域结束后会自动释放。当您构建程序时,编译器会发出管理堆栈内存的代码。