a simple question, but might not that easy

djwinter 2006-09-12 11:58:49
for some reason, in my program can not use malloc and new(becuase in a very special system, if the momory free or delet two times, system will freeze)

I use char a[20] instead
i wondering how to clear all the element after using a[]?
...全文
344 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Duwchy 2006-09-13
  • 打赏
  • 举报
回复
define and use it in a function, then it will be freed automatically after invoke the function.
hailongchang 2006-09-13
  • 打赏
  • 举报
回复
You can define it in a function (such as main function)as a local variable, which is allocated in the stack of the function.


Janlex 2006-09-13
  • 打赏
  • 举报
回复
if you just use char[], as the up-floor, the system will make clean the space int the stack when it finish in its space;

another , if you use 'new ' or 'malloc', the heap space did't free when the program is over. so you must use 'delete 'or 'free' to free the heap space by yourself.
Heaven_Redsky 2006-09-13
  • 打赏
  • 举报
回复
when you define char a[20], it is in stack, the system will clear it when you end your function. so take it easy.
Jokar 2006-09-13
  • 打赏
  • 举报
回复
I use char a[20] instead
i wondering how to clear all the element after using a[]?
============================================================
a[0]='\0';
sinall 2006-09-13
  • 打赏
  • 举报
回复
char a[20] is in stack,so u have no need clear it by yourself.

64,636

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧